SunImagePlugin fixes#2241
Conversation
SunImagePlugin now loads all the images here: https://samples.libav.org/image-samples/sunrast/ without LOAD_TRUNCATED_IMAGES set, verified visually. Prior to this commit: Could not open 32bpp.ras Could not open 4bpp.ras Could not open gray.ras Could not open lena-1bit-rle.sun Could not open lena-24bit-rle.sun Could not open lena-8bit-raw.sun Could not open lena-8bit-rle.sun Could not open MARBLES.SUN
|
If we can't include the test images in the source, one option is to zip them up onto https://github.com/python-pillow/pillow-depends and fetch them as part of the CI builds (and skip relevant tests if not present). |
|
Ok, tests should be good, I've rebased away the two extra xcopy flag commits, so I'm done with this one. |
| os.listdir(EXTRA_DIR) if os.path.splitext(f)[1] | ||
| in ('.sun', '.SUN', '.ras')) | ||
| for path in files: | ||
| print (path) |
| self.mode, rawmode = "RGB", "BGR" | ||
| elif depth == 32: | ||
| if file_type == 3: | ||
| self.mode, rawmode = 'RGB', 'RGBX' |
There was a problem hiding this comment.
Feel free to add a 32 bit type 3 file if you can find one.
| length = i32(s[28:32]) | ||
| offset = offset + length | ||
| self.palette = ImagePalette.raw("RGB;L", self.fp.read(length)) | ||
| raise SyntaxError("Unsupported Mode/Bit Depth") |
|
|
||
| if palette_length: | ||
| if palette_length > 1024: | ||
| raise SyntaxError("Unsupported Color Palette Length") |
| raise SyntaxError("Unsupported Color Palette Length") | ||
|
|
||
| if palette_type != 1: | ||
| raise SyntaxError("Unsupported Palette Type") |
There was a problem hiding this comment.
The palette bits are simple defensiveness. We're doing an unprotected read here, not even a saferead.
| self.tile = [("sun_rle", (0, 0)+self.size, offset, rawmode)] | ||
|
|
||
| else: | ||
| raise SyntaxError('Unsupported Sun Raster file type') |
There was a problem hiding this comment.
For all of the no-tests -- The values are in the spec, I have tested every sun raster file I've found. In this case, I'm raising a syntax error instead of just leaving the tile blank. It's an explanation rather than a silent failure. Previously hopper.ras silently here failed because it was a type 3, not type 1. So it passed through our open test, but when load was called, it barfed with a strange error. Fixing support for it meant that this change didn't get covered.
| raise SyntaxError("Unsupported Mode/Bit Depth") | ||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
Can delete some of these blank lines.
Fixes #2231
Changes proposed in this pull request:
Tests. I'd like to include the set of test images from https://samples.libav.org/image-samples/sunrast/ so that we don't regress. Libav is ok with mirroring/distribution, though half of the images are lena, and the others are of unclear license from upstream. So at least debian would have issues with them.