Skip to content

NegativeArraySizeException when reading GIF #351

@rzari

Description

@rzari

When attempting to read the attached GIF (random example) it returns the following:

Exception in thread "main" java.lang.NegativeArraySizeException
	at com.adobe.xmp.impl.ByteBuffer.<init>(Unknown Source)
	at com.drew.metadata.xmp.XmpReader.extract(XmpReader.java:167)
	at com.drew.metadata.gif.GifReader.readApplicationExtensionBlock(GifReader.java:275)
	at com.drew.metadata.gif.GifReader.readGifExtensionBlock(GifReader.java:225)
	at com.drew.metadata.gif.GifReader.extract(GifReader.java:103)
	at com.drew.imaging.gif.GifMetadataReader.readMetadata(GifMetadataReader.java:60)
	at com.drew.imaging.ImageMetadataReader.readMetadata(ImageMetadataReader.java:158)
	at com.drew.imaging.ImageMetadataReader.readMetadata(ImageMetadataReader.java:121)
	at com.drew.imaging.ImageMetadataReader.readMetadata(ImageMetadataReader.java:197)

Running the file against exiftool generates (partly to verify the filetype):

  • ExifTool Version Number : 10.93
  • File Name : IMG_5602.gif
  • Directory : /tmp
  • File Size : 44 kB
  • File Modification Date/Time : 2018:06:17 16:15:21+01:00
  • File Access Date/Time : 2018:06:17 16:15:30+01:00
  • File Inode Change Date/Time : 2018:06:17 16:15:21+01:00
  • File Permissions : rw-------
  • File Type : GIF
  • File Type Extension : gif
  • MIME Type : image/gif
  • GIF Version : 87a
  • Image Width : 840
  • Image Height : 436
  • Has Color Map : Yes
  • Color Resolution Depth : 8
  • Bits Per Pixel : 7
  • Background Color : 0
  • Warning : [minor] Empty XMP
  • Image Size : 840x436
  • Megapixels : 0.366

It looks like it could be an issue on this line in GifReader.java. In the case of the attached image, the XmpByte length is 4 bytes long so (xmpBytes.length - 257) raises the NegativeArraySizeException.

It looks like gatherBytes(SequentialReader reader) has a fixed byte array of size 257. Is there a reason that 257 is being subtracted from xmpBytes.length? Removing this appears to fix my issue but I'm not entirely familiar with the code.

Thanks.
img_5602

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions