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

ArrayIndexOutOfBoundsException 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 ArrayIndexOutOfBoundsException:

      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 GifImageParserCrash1 {
          public static byte[] btoa(String base64) {
              return Base64.getDecoder().decode(base64);
          }
      
          public static void main(String[] args) {
              byte[] input = btoa("SQAACklJAPVPAAIKACy3LAACAP8JAAD4AA==");
              try {
                  new GifImageParser().getBufferedImage(new ByteSourceArray(input), new HashMap<>());
              } catch (IOException | ImageReadException e) {}
          }
      }
      

      The stack trace is:

      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 4096 out of bounds for length 4096
              at org.apache.commons.imaging.common.mylzw.MyLzwDecompressor.initializeTable(MyLzwDecompressor.java:72)
              at org.apache.commons.imaging.common.mylzw.MyLzwDecompressor.<init>(MyLzwDecompressor.java:63)
              at org.apache.commons.imaging.common.mylzw.MyLzwDecompressor.<init>(MyLzwDecompressor.java:45)
              at org.apache.commons.imaging.formats.gif.GifImageParser.readImageDescriptor(GifImageParser.java:395)
              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 GifImageParserCrash1.main(GifImageParserCrash1.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: