Uploaded image for project: 'Commons Imaging'
  1. Commons Imaging
  2. IMAGING-278

IllegalArgumentException in MyLzwDecompressor

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.0-alpha2
    • None
    • Format: GIF
    • None

    Description

      The following Java snippet crashes with an IllegalArgumentException:

      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) {}
          }
      }
      
      

      The stack trace is:

      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)
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            Meumertzheim Fabian Meumertzheim
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: