Fix BigEndian + Refactoring + Optimization#7
Fix BigEndian + Refactoring + Optimization#7kkopachev wants to merge 7 commits intowiredfool:4641_rebasefrom
Conversation
src/libImaging/TiffDecode.c
Outdated
| TIFFGetField(tiff, TIFFTAG_TILELENGTH, &tile_length); | ||
|
|
||
| /* overflow check for row_byte_size calculation */ | ||
| if ((UINT32)INT_MAX / state->bits < tile_width) { |
There was a problem hiding this comment.
There's a UINT32_MAX, this will be 2^31 iirc. Are you aiming for 2^31 or 2^32?
There was a problem hiding this comment.
That's a good point.
I am going to check on this during this week.
I didn't change that check, just moved it into the function.
There was a problem hiding this comment.
Looked into that further and discovered that state->bytes is plain int, so can't hold uint32 values. Additionally, image dimensions (im->xsize, im->ysize) and dimensions on the state (state->x, state->y, state->xsize, ... ) are also int.
I decided to trust LibTiff's TIFFStripSize/TIFFTileSize to simplify calculations of row size in pixels and in bytes, since subsampled YCbCr images are handled in another case. These functions return tsize_t value which is same as size_t but signed.
Anyway, making sure that tile/strip dimensions and buffer bytes count are within INT_MAX seems safest.
However, switching to use TIFFStripSize/TIFFTileSize I saw crash tests crash, so had to put back check that LibTiff would return expected amount of data per tile/strip - hence 2 commits
973cb3f to
78c2739
Compare
|
Anything else I can do here so it makes it into Pillow, @wiredfool ? |
|
I'm not sure. This is in the queue, but I've got a security update that I want to get out and it's taking my time right now. I will say that I'm generally unamused with the way that the TiffReadRGBATile has different interpretations of sizes, and tends to cause an outsized proportion of security issues. I'm not sure if it's a defect in the way that we're calling it, or if there are underlying issues with the implementation in libtiff. |
|
I thought it was good idea to pull upstream master into this, but figured base branch to this is not updated. It showed a bunh of commits from master. I reverted back after tests completed. |
|
In last commit I supplied actual strip size in bytes we expect to TIFFReadEncodedStrip so it fails if for some reason strip extends to outside of our buffer. |
|
Cherrypicked into https://github.com/python-pillow/Pillow/pull/5364/files |
After trying to dig around python-pillow#5178 to fix windows 32bit issue, I found out that there are few tweaks to make.
(might be easier to review by commit)