Opened 9 years ago

Closed 9 years ago

#24544 closed Cleanup/optimization (fixed)

core.files.images.get_image_dimensions broken on some valid PNG images

Reported by: artscoop Owned by: nobody
Component: File uploads/storage Version: 1.7
Severity: Normal Keywords: PIL
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description (last modified by artscoop)

Hi,
second time I find a bug in the same function. Here, the function failed (exception raised and not caught) on a valid PNG file (this image: https://mega.co.nz/#!W0tXzBAK!iLprbqkVWFAzfcn2GUDRGHiH8Pxyi4DxCQi580shcec).
The error raised by PIL is a struct.error, which should be expected but is not caught by the chunk feeder loop.

The feeder knows this

            except zlib.error as e:
                # ignore zlib complaining on truncated stream, just feed more
                # data to parser (ticket #19457).
                if e.args[0].startswith("Error -5"):
                    pass
                else:
                    raise

but does not know this

from struct import error
...

except struct.error:
    pass

when you catch the proper exception, the file header fed to the parser becomes correct starting at offset 9214.
The good news is, it does not need tests.

Attachments (1)

b.png (20.5 KB ) - added by artscoop 9 years ago.
Valid but faulty image

Download all attachments as: .zip

Change History (7)

by artscoop, 9 years ago

Attachment: b.png added

Valid but faulty image

comment:1 by artscoop, 9 years ago

Description: modified (diff)

comment:3 by Paul Hallett, 9 years ago

Needs tests: set

comment:4 by Tim Graham, 9 years ago

Has patch: set
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

comment:5 by Tim Graham, 9 years ago

Needs tests: unset
Patch needs improvement: set

comment:6 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: newclosed

In 2fc19b92:

Fixed #24544 -- Fixed get_image_dimensions() on image buffers that Pillow fails to parse.

Thanks Steve Kossouho for the report and original patch.

Note: See TracTickets for help on using tickets.
Back to Top