Roughsketch/imagesize

Wrong dimensions for specific JPEG

Closed this issue · 3 comments

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.

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.

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.

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