Reputation: 71
I tried to catch truncated JPEG or PNG images by checking if the last bytes of the image has EOI marker (for JPEG is was 'ffd9' in last 2 bytes, and for PNG it was '49454e44ae426082' in last 8 bytes)
But I found that this approach cannot work all the time because of extra data in the image. Some images include extra bytes after EOI....
Is there an offset for the EOI so I can stick with this bytes comparing solution? or do I have to find another way to check if image is truncated?
I cannot use try-except by using global variable PIL LOAD_TRUNCATED_IMAGES because my process is based on multi-thread context.
It would be nice if I can find solution for all JPEG, PNG images.
Upvotes: 1
Views: 1054
Reputation: 71
I found out the reason why normal JPEG image did not end with EOI. There are some images which have a data after its EOI. It's called tailer.
PNG also has that kind of things so if you deal with different type of images you should know about the variations of the data around EOI.
Upvotes: 1