drewnoakes / metadata-extractor

Extracts Exif, IPTC, XMP, ICC and other metadata from image, video and audio files
Apache License 2.0
2.59k stars 484 forks source link

Observed multiple instances of PNG chunk 'eXIf', for which multiples are not allowed #683

Open Nathipha opened 1 month ago

Nathipha commented 1 month ago

Java 8, metadata-extractor 2.19.0, xmpcore 6.1.11 I'm trying to read the metadata of this png image (also attached it) with the following code:

String input = "C:\\misc\\EXIF\\testimgs\\Minions-png-1.png";

try {
    File img = new File(input);
    Metadata meta = ImageMetadataReader.readMetadata(img);
} catch(Exception e) {
    e.printStackTrace();
}

...but it's throwing an Exception:

com.drew.imaging.png.PngProcessingException: Observed multiple instances of PNG chunk 'eXIf', for which multiples are not allowed
    at com.drew.imaging.png.PngChunkReader.extract(PngChunkReader.java:115)
    at com.drew.imaging.png.PngMetadataReader.readMetadata(PngMetadataReader.java:103)
    at com.drew.imaging.ImageMetadataReader.readMetadata(ImageMetadataReader.java:157)
    at com.drew.imaging.ImageMetadataReader.readMetadata(ImageMetadataReader.java:124)
    at com.drew.imaging.ImageMetadataReader.readMetadata(ImageMetadataReader.java:204)
    at Main.main(Main.java:41)

This seems to be the same as in the second to last post in this issue thread (but the other poster hasn't created his own issue yet).

How do I go about fixing this?

Minions-png-1

drewnoakes commented 1 month ago

On a phone so don't have full context, but my sense is that maybe we can loosen the restriction here and tolerate invalid data.

Certain chunks are not allowed to exist more than once, and the library is enforcing that. Some software must have produced invalid PNG data.

There are lots of ways data can be invalid. It happens. We generally try to tolerate and continue in the face of such errors.

If you want to dig into the details and see about making a PR I'll be happy to help review and merge.

Nathipha commented 1 month ago

Oh, so that means that that is a broken .png? Image viewers (even the Windows one) and PaintShopPro are able to open it just fine. How do I fix the image or make sure that I don't get the same problem with other images too, is there a parameter I can set in the library to just ignore this specific one?

How would I go about fixing this in code, I've got no idea where to even start tbh.