You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Fabian Meumertzheim (Jira)" <ji...@apache.org> on 2021/01/14 09:23:01 UTC

[jira] [Created] (IMAGING-278) IllegalArgumentException in MyLzwDecompressor

Fabian Meumertzheim created IMAGING-278:
-------------------------------------------

             Summary: IllegalArgumentException in MyLzwDecompressor 
                 Key: IMAGING-278
                 URL: https://issues.apache.org/jira/browse/IMAGING-278
             Project: Commons Imaging
          Issue Type: Bug
          Components: Format: GIF
    Affects Versions: 1.0-alpha2
            Reporter: Fabian Meumertzheim


The following Java snippet crashes with an IllegalArgumentException:
{code:java}
import java.io.IOException;
import java.util.Base64;
import java.util.HashMap;

import org.apache.commons.imaging.ImageReadException;
import org.apache.commons.imaging.common.bytesource.ByteSourceArray;
import org.apache.commons.imaging.formats.gif.GifImageParser;

public class GifImageParserCrash2 {
    public static byte[] btoa(String base64) {
        return Base64.getDecoder().decode(base64);
    }

    public static void main(String[] args) {
        byte[] input = btoa("AAAAAAAAAAAp/QIKACwAgAD4Kf///iIAAA==");
        try {
            new GifImageParser().getBufferedImage(new ByteSourceArray(input), new HashMap<>());
        } catch (IOException | ImageReadException e) {}
    }
}

{code}

The stack trace is:
{noformat}
Exception in thread "main" java.lang.IllegalArgumentException: Negative initial size: -30877737
        at java.base/java.io.ByteArrayOutputStream.<init>(ByteArrayOutputStream.java:78)
        at org.apache.commons.imaging.common.mylzw.MyLzwDecompressor.decompress(MyLzwDecompressor.java:144)
        at org.apache.commons.imaging.formats.gif.GifImageParser.readImageDescriptor(GifImageParser.java:397)
        at org.apache.commons.imaging.formats.gif.GifImageParser.readBlocks(GifImageParser.java:261)
        at org.apache.commons.imaging.formats.gif.GifImageParser.readFile(GifImageParser.java:475)
        at org.apache.commons.imaging.formats.gif.GifImageParser.readFile(GifImageParser.java:459)
        at org.apache.commons.imaging.formats.gif.GifImageParser.getBufferedImage(GifImageParser.java:840)
        at GifImageParserCrash2.main(GifImageParserCrash2.java:17)
{noformat}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)