From b28f43fa8409e1648c4e727d096948d2ef5c3f22 Mon Sep 17 00:00:00 2001 From: Milan Nikl Date: Wed, 28 Apr 2021 13:39:24 +0200 Subject: [PATCH 1/4] Comparing PNG chunk size to available bytes in buffer --- Source/com/drew/imaging/png/PngChunkReader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/com/drew/imaging/png/PngChunkReader.java b/Source/com/drew/imaging/png/PngChunkReader.java index cbc4e5de5..69a4d54bb 100644 --- a/Source/com/drew/imaging/png/PngChunkReader.java +++ b/Source/com/drew/imaging/png/PngChunkReader.java @@ -86,7 +86,7 @@ public Iterable extract(@NotNull final SequentialReader reader, @Nulla // Process the next chunk. int chunkDataLength = reader.getInt32(); - if (chunkDataLength < 0) + if ((chunkDataLength < 0) || (chunkDataLength > reader.available())) throw new PngProcessingException("PNG chunk length exceeds maximum"); PngChunkType chunkType = new PngChunkType(reader.getBytes(4)); From e116370feae466cd42f5d93ba775121868a12f58 Mon Sep 17 00:00:00 2001 From: Milan Nikl Date: Mon, 3 May 2021 11:23:38 +0200 Subject: [PATCH 2/4] Only copying chunk data for specified chunk types - Reverted stream available bytes check - Updated tests using corrupted png file --- .../com/drew/imaging/png/PngChunkReader.java | 16 +++++++++-- Tests/Data/icon-96x96-corrupted-data.png | Bin 0 -> 8556 bytes .../drew/imaging/png/PngChunkReaderTest.java | 25 ++++++++++++++++-- .../imaging/png/PngMetadataReaderTest.java | 6 +++++ 4 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 Tests/Data/icon-96x96-corrupted-data.png diff --git a/Source/com/drew/imaging/png/PngChunkReader.java b/Source/com/drew/imaging/png/PngChunkReader.java index 69a4d54bb..c8a4db064 100644 --- a/Source/com/drew/imaging/png/PngChunkReader.java +++ b/Source/com/drew/imaging/png/PngChunkReader.java @@ -69,6 +69,12 @@ public Iterable extract(@NotNull final SequentialReader reader, @Nulla // Miscellaneous information: bKGD, hIST, pHYs, sPLT // Time information: tIME // + // CHUNK READING + // + // Only chunk data for types specified in desiredChunkTypes is extracted. + // For empty chunk type list NO data is copied from source stream. + // For null chunk type list ALL data is copied from source stream. + // reader.setMotorolaByteOrder(true); // network byte order @@ -86,14 +92,20 @@ public Iterable extract(@NotNull final SequentialReader reader, @Nulla // Process the next chunk. int chunkDataLength = reader.getInt32(); - if ((chunkDataLength < 0) || (chunkDataLength > reader.available())) + if (chunkDataLength < 0) throw new PngProcessingException("PNG chunk length exceeds maximum"); PngChunkType chunkType = new PngChunkType(reader.getBytes(4)); boolean willStoreChunk = desiredChunkTypes == null || desiredChunkTypes.contains(chunkType); - byte[] chunkData = reader.getBytes(chunkDataLength); + byte[] chunkData; + if (willStoreChunk) { + chunkData = reader.getBytes(chunkDataLength); + } else { + chunkData = null; // To satisfy the compiler + reader.skip(chunkDataLength); + } // Skip the CRC bytes at the end of the chunk // TODO consider verifying the CRC value to determine if we're processing bad data diff --git a/Tests/Data/icon-96x96-corrupted-data.png b/Tests/Data/icon-96x96-corrupted-data.png new file mode 100644 index 0000000000000000000000000000000000000000..91a180626a60a46da1a420eb8394d06b97caf0dc GIT binary patch literal 8556 zcmZ{J1yEc~v-V;^fT(1A#yccZV#l z|Gu~Ws{7qrb?cltQ#1W^_sp4@?mm5zbhK262-rUC%an*Q|81_#~7@YPd+0-BHvyXXcBOjS=400`j(0HR_6fE#pI)D8gP4+H@A ztN{Q>J^(=NRn(&^jV3&?eW{`Zc>MP&{Z#!H-GlF?YU&FBJf--zU;qk>XaE4FJvAi- zgP>oBmb)SJYHw1d_t<&5L$@$4Ko^Y{UmSlwH&rRQ#gccRs=Sy9FfUSh7;t15Ne%zHsev*w%x~xPEpyH^IMX(F6_un!3yWZWK#oX@MX$@HPAcdGaxhl=bBVYx|SwRXjMDLxvs*S})6pZMV8J{nq;W z5#{x&pY1u@bFN=F?QA*}67&}Lnl-z(2T|fWL>rnXf~CXFJa9U(2v6VzTKK5+g+%d_ zqHVJ6*~DNvV7d%iA2>tg2KlWCNN48C{e@Vy{YFvagmo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=4qk*Zz&vy%C3eMb+fh!J4Q>>~% zwJ5v;z&u{#w>XLkR``hwrO)T(Wx6X_u5EH|!E!CrQzuz!^#RHlj@Y<9R}-z(lMjoq z;=SqEcBXUIi#iqcz3HhW9#nyh|C3cD*Y+#Z_^Sb2cZ=h*KNlH+kEMu_%#iB{j2)?q z*wZ?b&1guwSLOrk<-UiH;GgipN%x`aQ;m1Xfq<%_0M{#tP}*NkY0G<27W>l|iL_KY zizdwM5csXxX5!qWJEu89vF6&G@#MzkA$eFqQppcU&kaaV zKTB(G1*@5rzppa`tMVCl`pDMcMO?~c%Qk6rMA8=Ay@f>CaxjbaxmhOT%VN>Oi%xsp z5k>sp0xQax;zN9TiYjDJcg+6A3ZBW zsLDTIConR_4@PdBe|W%2>*O$IPgRv~aDnI=Ovb+SRIoK~z>N5xnfmqp zL2vmM!|!UI*NuN}LE_#xeF6Mq%z z{1f4j`6zcBH9uWfl8@TDoJ processFile(String filePath) throws PngProcessingException, IOException + + public static List processFile(String filePath) + throws PngProcessingException, IOException { + return processFile(filePath, null); + } + + public static List processFile(String filePath, Set desiredChunkTypes) + throws PngProcessingException, IOException { FileInputStream inputStream = null; try { inputStream = new FileInputStream(filePath); - return Iterables.toList(new PngChunkReader().extract(new StreamReader(inputStream), null)); + return Iterables.toList(new PngChunkReader().extract(new StreamReader(inputStream), + desiredChunkTypes)); } finally { if (inputStream != null) { inputStream.close(); @@ -96,4 +108,13 @@ public void testExtractPhotoshop() throws Exception assertEquals(PngChunkType.IEND, chunks.get(4).getType()); assertEquals(0, chunks.get(4).getBytes().length); } + + @Test(expected = EOFException.class) + public void testCorruptedFile() throws Exception + { + // One desired chunk specified, only given chunk read, other types skipped. + Set desiredChunkTypes = new HashSet<>(); + desiredChunkTypes.add(PngChunkType.IHDR); + processFile("Tests/Data/icon-96x96-corrupted-data.png", desiredChunkTypes); + } } diff --git a/Tests/com/drew/imaging/png/PngMetadataReaderTest.java b/Tests/com/drew/imaging/png/PngMetadataReaderTest.java index a32f6e469..7d07a6792 100644 --- a/Tests/com/drew/imaging/png/PngMetadataReaderTest.java +++ b/Tests/com/drew/imaging/png/PngMetadataReaderTest.java @@ -24,6 +24,7 @@ import com.drew.lang.annotations.NotNull; import com.drew.metadata.Metadata; import com.drew.metadata.png.PngDirectory; +import java.io.EOFException; import org.junit.Test; import java.io.FileInputStream; @@ -114,4 +115,9 @@ public void testGimpGreyscaleWithManyChunks() throws Exception TimeZone.setDefault(timeZone); } } + + @Test(expected = EOFException.class) + public void corruptedFileTest() throws PngProcessingException, IOException { + processFile("Tests/Data/icon-96x96-corrupted-data.png"); + } } From c588b9568cb75313f7005b4f32ecb51672ae1f29 Mon Sep 17 00:00:00 2001 From: Milan Nikl Date: Mon, 3 May 2021 11:42:57 +0200 Subject: [PATCH 3/4] Fixing diamond operator for Java 1.6 compatibility --- Tests/com/drew/imaging/png/PngChunkReaderTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/com/drew/imaging/png/PngChunkReaderTest.java b/Tests/com/drew/imaging/png/PngChunkReaderTest.java index 510df5863..e64a7a4df 100644 --- a/Tests/com/drew/imaging/png/PngChunkReaderTest.java +++ b/Tests/com/drew/imaging/png/PngChunkReaderTest.java @@ -113,7 +113,7 @@ public void testExtractPhotoshop() throws Exception public void testCorruptedFile() throws Exception { // One desired chunk specified, only given chunk read, other types skipped. - Set desiredChunkTypes = new HashSet<>(); + Set desiredChunkTypes = new HashSet(); desiredChunkTypes.add(PngChunkType.IHDR); processFile("Tests/Data/icon-96x96-corrupted-data.png", desiredChunkTypes); } From 6247ec7f9487c54be66f3ba3a668a7302d8906f7 Mon Sep 17 00:00:00 2001 From: Milan Nikl Date: Tue, 4 May 2021 08:06:51 +0200 Subject: [PATCH 4/4] Removed tests with corrupted image as it should be placed into image repository instead. --- Tests/Data/icon-96x96-corrupted-data.png | Bin 8556 -> 0 bytes .../drew/imaging/png/PngChunkReaderTest.java | 25 ++---------------- .../imaging/png/PngMetadataReaderTest.java | 6 ----- 3 files changed, 2 insertions(+), 29 deletions(-) delete mode 100644 Tests/Data/icon-96x96-corrupted-data.png diff --git a/Tests/Data/icon-96x96-corrupted-data.png b/Tests/Data/icon-96x96-corrupted-data.png deleted file mode 100644 index 91a180626a60a46da1a420eb8394d06b97caf0dc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8556 zcmZ{J1yEc~v-V;^fT(1A#yccZV#l z|Gu~Ws{7qrb?cltQ#1W^_sp4@?mm5zbhK262-rUC%an*Q|81_#~7@YPd+0-BHvyXXcBOjS=400`j(0HR_6fE#pI)D8gP4+H@A ztN{Q>J^(=NRn(&^jV3&?eW{`Zc>MP&{Z#!H-GlF?YU&FBJf--zU;qk>XaE4FJvAi- zgP>oBmb)SJYHw1d_t<&5L$@$4Ko^Y{UmSlwH&rRQ#gccRs=Sy9FfUSh7;t15Ne%zHsev*w%x~xPEpyH^IMX(F6_un!3yWZWK#oX@MX$@HPAcdGaxhl=bBVYx|SwRXjMDLxvs*S})6pZMV8J{nq;W z5#{x&pY1u@bFN=F?QA*}67&}Lnl-z(2T|fWL>rnXf~CXFJa9U(2v6VzTKK5+g+%d_ zqHVJ6*~DNvV7d%iA2>tg2KlWCNN48C{e@Vy{YFvagmoZT_-10{l~{uPqW4G7E&=+Z zfP|mmGv)a&#G2fC@>*k(?|=H94lG9(B2uuJbTvKJL^3cc;m@p7V?^mbb?k(uc<%ty zWVBFGDCeQs;DK5D0hIl~rt~V9D8HI%{ReDgaoV3M7p1Tt#Z7#I@$qTzH^$uWtB9kn zC8N{>C0D}KOkh>%%C3hmcdn)>h9ouRg-Ks{^PiJ&hNy*_DjH_WfcAO2yQBWA*{E6P zKC}kZY$}Pih^&Q!g&+kIl^DDSN(*1aD6S=Tg6jCozsLH4G23Rd!yhN4PxhU)A2oO# zMM|NUWyx}UvKk)FHFx%%IHCOj0ZJFU~=RW5>Z;0-J+`AF-kob}T zB4JWYR;p^3=bq&jPhW_vN4SFH5q!srC>f$p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IConR_4@PdBe|W%2>*O$IPgRv~aDnI=Ovb+SRIoK~z>N5xnfmqp zL2vmM!|!UI*NuN}LE_#xeF6Mq%z z{1f4j`6zcBH9uWfl8@TDoJ processFile(String filePath) - throws PngProcessingException, IOException { - return processFile(filePath, null); - } - - public static List processFile(String filePath, Set desiredChunkTypes) - throws PngProcessingException, IOException + public static List processFile(String filePath) throws PngProcessingException, IOException { FileInputStream inputStream = null; try { inputStream = new FileInputStream(filePath); - return Iterables.toList(new PngChunkReader().extract(new StreamReader(inputStream), - desiredChunkTypes)); + return Iterables.toList(new PngChunkReader().extract(new StreamReader(inputStream), null)); } finally { if (inputStream != null) { inputStream.close(); @@ -108,13 +96,4 @@ public void testExtractPhotoshop() throws Exception assertEquals(PngChunkType.IEND, chunks.get(4).getType()); assertEquals(0, chunks.get(4).getBytes().length); } - - @Test(expected = EOFException.class) - public void testCorruptedFile() throws Exception - { - // One desired chunk specified, only given chunk read, other types skipped. - Set desiredChunkTypes = new HashSet(); - desiredChunkTypes.add(PngChunkType.IHDR); - processFile("Tests/Data/icon-96x96-corrupted-data.png", desiredChunkTypes); - } } diff --git a/Tests/com/drew/imaging/png/PngMetadataReaderTest.java b/Tests/com/drew/imaging/png/PngMetadataReaderTest.java index 7d07a6792..a32f6e469 100644 --- a/Tests/com/drew/imaging/png/PngMetadataReaderTest.java +++ b/Tests/com/drew/imaging/png/PngMetadataReaderTest.java @@ -24,7 +24,6 @@ import com.drew.lang.annotations.NotNull; import com.drew.metadata.Metadata; import com.drew.metadata.png.PngDirectory; -import java.io.EOFException; import org.junit.Test; import java.io.FileInputStream; @@ -115,9 +114,4 @@ public void testGimpGreyscaleWithManyChunks() throws Exception TimeZone.setDefault(timeZone); } } - - @Test(expected = EOFException.class) - public void corruptedFileTest() throws PngProcessingException, IOException { - processFile("Tests/Data/icon-96x96-corrupted-data.png"); - } }