[OpenJDK 2D-Dev]  RFR JDK-8190997: PNGImageReader throws NullPointerException when PLTE section is missing
Jayathirth D V
jayathirth.d.v at oracle.com
Wed Dec 13 10:50:10 UTC 2017
Thanks for your inputs.
I have updated the code based on your inputs.
Please find updated webrev for review:
From: Prahalad Kumar Narayanan
Sent: Wednesday, December 13, 2017 3:29 PM
To: Jayathirth D V; 2d-dev
Subject: RE: [OpenJDK 2D-Dev]  RFR JDK-8190997: PNGImageReader throws NullPointerException when PLTE section is missing
I looked into the changes.
The logic to check the presence of PLTE chunk is correct.
Few minor changes
. The if condition to check whether PLTE chunk exists would get executed every time an IDAT chunk is encountered.
. For png images with multiple IDAT chunks, this is a repeated check and can be avoided.
. You can move the if condition within the if block that stores location of 1st IDAT chunk.
. Secondly, the wording within the IIOException can be changed.
. PNG specification mentions IHDR chunk as Image Header and this is separate from PLTE chunk.
. So you could rephrase "PNG Header doesn't contain required PLTE chunk" as "PNG image doesn't contain required PLTE chunk"
Have a good day
----- Original Message -----
From: Jayathirth D V
Sent: Wednesday, December 13, 2017 3:02 PM
Subject: [OpenJDK 2D-Dev]  RFR JDK-8190997: PNGImageReader throws NullPointerException when PLTE section is missing
Please review the following fix in JDK10 :
Bug : https://bugs.openjdk.java.net/browse/JDK-8190997
Webrev : http://cr.openjdk.java.net/~jdv/8190997/webrev.00/
Issue : When we try to read PNG image with color type as PNG_COLOR_PALETTE in IHDR header but missing the required PLTE chunk we throw NullPointerException.
Root cause : We finish reading metadata but when we try to read image information and access palette related data it throws NPE as palette related data is not initialized/not present.
Solution : PNG specification mandates that if color type present in IHDR is PNG_COLOR_PALETTE(type 3), PLTE chunk should appear before the first IDAT chunk. So while reading metadata itself we should verify the same and if required PLTE chunk is absent we should throw proper IIOException instead of allowing the code to continue further and throw NPE while trying to access palette information.
More information about the 2d-dev