Roughsketch / imagesize

Quickly probe the size of various image formats without reading the entire file.
MIT License
57 stars 12 forks source link

Wrong dimensions for specific JPEG #11

Closed sudo-nice closed 4 years ago

sudo-nice commented 4 years ago

This image reported to be 52351x52319, while it's actually 1080x1080.

If it helps, I discovered a similar library for Ruby, which obtains dimensions correctly. Maybe, it would be possible to get some inspiration from.

Roughsketch commented 4 years ago

It looks like the root cause of this is due to the image starting with an EXIF section rather than a JFIF and it contains data that the library interprets as markers when they aren't. The same issue is also in the image you posted on #10 recently.

I'll have to rewrite the JPEG parser to fix this, but I've been reading the JPEG spec closer and I have a solid idea on what to do. I'll try to get this done after work.

Roughsketch commented 4 years ago

Both images were added to new tests and JPEG handling has been rewritten. It now reads tag lengths and skips over their entire length if it doesn't match a dimension tag instead of just finding all instances of FF XX.

Tests show everything is fine, but please let me know if this solves the issue. This should also prevent similar but slightly different images from breaking it.

sudo-nice commented 4 years ago

The new version works fine for all the images I have. Thank you very much!