Skip to content

Conversation

mrserb
Copy link
Member

@mrserb mrserb commented Sep 16, 2025

Additional checks were recently added to ICC_Profile (see JDK-8347377). As a result, objects previously stored as valid profiles may now throw an IllegalArgumentException during serialization. Discussion about serialization was started in #23044 but it seems at the end non-serialization related check was verified. =(

The patch itself is simple, but I found that we do not have good test coverage in this area. So I added two tests to cover all possible variants specified by the serialization spec.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Warnings

 ⚠️ Patch contains a binary file (test/jdk/java/awt/color/ICC_Profile/Serialization/SerializationSpecTest/empty.ser)
 ⚠️ Patch contains a binary file (test/jdk/java/awt/color/ICC_Profile/Serialization/SerializationSpecTest/invalid.ser)
 ⚠️ Patch contains a binary file (test/jdk/java/awt/color/ICC_Profile/Serialization/SerializationSpecTest/invalid_invalid.ser)
 ⚠️ Patch contains a binary file (test/jdk/java/awt/color/ICC_Profile/Serialization/SerializationSpecTest/invalid_null.ser)
 ⚠️ Patch contains a binary file (test/jdk/java/awt/color/ICC_Profile/Serialization/SerializationSpecTest/invalid_valid.ser)
 ⚠️ Patch contains a binary file (test/jdk/java/awt/color/ICC_Profile/Serialization/SerializationSpecTest/invalid_wrongType.ser)
 ⚠️ Patch contains a binary file (test/jdk/java/awt/color/ICC_Profile/Serialization/SerializationSpecTest/null.ser)
 ⚠️ Patch contains a binary file (test/jdk/java/awt/color/ICC_Profile/Serialization/SerializationSpecTest/null_invalid.ser)
 ⚠️ Patch contains a binary file (test/jdk/java/awt/color/ICC_Profile/Serialization/SerializationSpecTest/null_null.ser)
 ⚠️ Patch contains a binary file (test/jdk/java/awt/color/ICC_Profile/Serialization/SerializationSpecTest/null_wrongType.ser)
 ⚠️ Patch contains a binary file (test/jdk/java/awt/color/ICC_Profile/Serialization/SerializationSpecTest/valid.ser)
 ⚠️ Patch contains a binary file (test/jdk/java/awt/color/ICC_Profile/Serialization/SerializationSpecTest/valid_valid.ser)
 ⚠️ Patch contains a binary file (test/jdk/java/awt/color/ICC_Profile/Serialization/SerializationSpecTest/valid_wrongType.ser)
 ⚠️ Patch contains a binary file (test/jdk/java/awt/color/ICC_Profile/Serialization/SerializationSpecTest/wrongType.ser)
 ⚠️ Patch contains a binary file (test/jdk/java/awt/color/ICC_Profile/Serialization/SerializationSpecTest/wrongType_invalid.ser)
 ⚠️ Patch contains a binary file (test/jdk/java/awt/color/ICC_Profile/Serialization/SerializationSpecTest/wrongType_null.ser)
 ⚠️ Patch contains a binary file (test/jdk/java/awt/color/ICC_Profile/Serialization/SerializationSpecTest/wrongType_valid.ser)
 ⚠️ Patch contains a binary file (test/jdk/java/awt/color/ICC_Profile/Serialization/SerializationSpecTest/wrongType_wrongType.ser)

Issue

  • JDK-8367384: The ICC_Profile class may throw exceptions during serialization (Bug - P3)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/27326/head:pull/27326
$ git checkout pull/27326

Update a local copy of the PR:
$ git checkout pull/27326
$ git pull https://git.openjdk.org/jdk.git pull/27326/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 27326

View PR using the GUI difftool:
$ git pr show -t 27326

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/27326.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 16, 2025

👋 Welcome back serb! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Sep 16, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk
Copy link

openjdk bot commented Sep 16, 2025

@mrserb The following label will be automatically applied to this pull request:

  • client

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@mrserb mrserb marked this pull request as ready for review September 17, 2025 03:39
@openjdk openjdk bot added the rfr Pull request is ready for review label Sep 17, 2025
case null, default -> getInstance(data);
};
} catch (ClassCastException | IllegalArgumentException e) {
throw new InvalidObjectException("Invalid ICC Profile Data", e);
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is possibility for optimization here, because we do not actually need to read the "data" if "csName" is a valid constant for the standard profile. However, the spec does not seem to say anything about the optionality of the data field itself, only about the content of the data. So, I left this part unchanged.

@mlbridge
Copy link

mlbridge bot commented Sep 17, 2025

Webrevs

case "CS_LINEAR_RGB" -> getInstance(ColorSpace.CS_LINEAR_RGB);
case null, default -> getInstance(data);
};
} catch (ClassCastException | IllegalArgumentException e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see InvalidObjectException as a declared exception either for
This is a little tricky InvalidObjectException isn't listed explicitly by
https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/io/ObjectInputStream.html#readObject()
although it is a subclass of IOException
https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/io/InvalidObjectException.html#%3Cinit%3E(java.lang.String)

However the docs for
https://docs.oracle.com/en/java/javase/25/docs/api/java.desktop/java/awt/color/ICC_Profile.html#getInstance(byte%5B%5D)

say that IOException is thrown by ObjectInputStream
* @throws IOException thrown by {@code ObjectInputStream}
but the exceptions you are catching are from the profile verifier - at least the IAE is.
And there is a (closed) test that expects IAE in this case and fails because it now gets InvalidObjectException

Either that test, or this fix, or both will need revising. Perhaps the spec. of readObject should be updated too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see InvalidObjectException as a declared exception either for This is a little tricky InvalidObjectException isn't listed explicitly by https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/io/ObjectInputStream.html#readObject() although it is a subclass of IOException https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/io/InvalidObjectException.html#%3Cinit%3E(java.lang.String)

Throwing "new InvalidObjectException" from readObject for certain issues is a common pattern in the java.base and java.desktop modules. The assumption seems to be that InvalidObjectException is treated as a kind of io error(IOException), since it is usually thrown when the data is “broken” and cannot be saved by the corresponding write method. The specification for "ObjectInputStream.readObject()" could be updated to mention this behavior.

However the docs for https://docs.oracle.com/en/java/javase/25/docs/api/java.desktop/java/awt/color/ICC_Profile.html#getInstance(byte%5B%5D)

say that IOException is thrown by ObjectInputStream * @throws IOException thrown by {@code ObjectInputStream} but the exceptions you are catching are from the profile verifier - at least the IAE is. And there is a (closed) test that expects IAE in this case and fails because it now gets InvalidObjectException

Either that test, or this fix, or both will need revising. Perhaps the spec. of readObject should be updated too.

That closed test should be updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client [email protected] rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

2 participants