[ 
https://issues.apache.org/jira/browse/IMAGING-222?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16840904#comment-16840904
 ] 

Bruno P. Kinoshita commented on IMAGING-222:
--------------------------------------------

And running the current code from the master branch, I actually get an 
`IOException`:
{noformat}
Caused by: java.io.IOException: Could not read marker
    at 
org.apache.commons.imaging.common.BinaryFunctions.readByte(BinaryFunctions.java:78)
    at 
org.apache.commons.imaging.formats.jpeg.JpegUtils.traverseJFIF(JpegUtils.java:64)
    at 
org.apache.commons.imaging.formats.jpeg.JpegImageParser.readSegments(JpegImageParser.java:202)
    at 
org.apache.commons.imaging.formats.jpeg.JpegImageParser.readSegments(JpegImageParser.java:280)
    at 
org.apache.commons.imaging.formats.jpeg.JpegImageParser.getExifRawData(JpegImageParser.java:365)
    at 
org.apache.commons.imaging.formats.jpeg.JpegImageParser.getExifMetadata(JpegImageParser.java:347)
    at 
org.apache.commons.imaging.formats.jpeg.JpegImageParser.getMetadata(JpegImageParser.java:316)
    at org.apache.commons.imaging.Imaging.getMetadata(Imaging.java:1146)
    at org.apache.commons.imaging.Imaging.getMetadata(Imaging.java:1139)
    at 
org.apache.commons.imaging.formats.jpeg.JpegWithNegativeArraySize.testNegativeArraySizeImage(JpegWithNegativeArraySize.java:40)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at 
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at 
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at 
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at 
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at 
org.junit.internal.runners.statements.ExpectException.evaluate(ExpectException.java:19)
    ... 15 more

{noformat}
Which I believe is OK, as it is declared in the method signature it may throw 
ImageReadException (which appears to be used for invalid segment length, and 
other structural problems), or IOException. The IOException is thrown from the 
readByte method, which is declared to throw only IOException, when it fails to 
read the bytes.

Closing as Won't fix, but feel free to re-open in case the error persists.

Cheers

Bruno

> JPEG segment size not validated
> -------------------------------
>
>                 Key: IMAGING-222
>                 URL: https://issues.apache.org/jira/browse/IMAGING-222
>             Project: Commons Imaging
>          Issue Type: Bug
>          Components: Format: JPEG
>            Reporter: Le Huu Quang Linh
>            Assignee: Bruno P. Kinoshita
>            Priority: Major
>             Fix For: 1.0-alpha2
>
>         Attachments: NegSegment.jpg
>
>
> Using my AFL-based fuzzer for Java. I found that a NegativeArraySizeException 
> may be throw when attempting to read an invalid JPEG image.
> {code:java}
> public void traverseJFIF(final ByteSource byteSource, final Visitor visitor)
>             throws ImageReadException,
>             IOException {
>         try (InputStream is = byteSource.getInputStream()) {
>             readAndVerifyBytes(is, JpegConstants.SOI,
>                     "Not a Valid JPEG File: doesn't begin with 0xffd8");
> .....
> {code}
> I think you should add the handle NegativeArraySizeException exception



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to