Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit TIFF strip size when saving with LibTIFF #5514

Merged
merged 5 commits into from Jun 30, 2021

Conversation

kmilos
Copy link
Contributor

@kmilos kmilos commented May 27, 2021

Addresses #5370 partly.

Doesn't really "fix" the loading of any existing >2GB single strip images (would need to handle specially by buffered read in decoder), but reduces their incidence as recommended by the TIFF spec.

@radarhere radarhere added the TIFF label May 27, 2021
@kmilos
Copy link
Contributor Author

kmilos commented May 28, 2021

Ah, in the process a new bug was uncovered - the updated test sequence with grayscale conversion:

        info = im.tag_v2

        # Resize the image so that STRIPBYTECOUNTS will be larger than a SHORT (64 KB exactly)
        im = im.convert("L").resize((512, 512))

        # STRIPBYTECOUNTS can be a SHORT or a LONG
        info.tagtype[TiffImagePlugin.STRIPBYTECOUNTS] = TiffTags.SHORT

        im.save(out, tiffinfo=info)

produces an invalid TIFF where some of the original tag values are not overwritten: SamplesPerPixel are still 3, and ImageWidth and ImageHeight still 128...

@kmilos
Copy link
Contributor Author

kmilos commented May 28, 2021

Still work to do: StripOffsets and StripByteCounts are assumed to be just single values instead of being derived and stored as arrays if multiple strips are present.

@kmilos kmilos marked this pull request as draft May 28, 2021 08:50
@kmilos kmilos force-pushed the fix_tiff_rowsperstrip branch 2 times, most recently from 820997e to 4b5488c Compare June 2, 2021 09:16
@kmilos kmilos changed the title Limit TIFF strip size when saving Limit TIFF strip size when saving with libtiff Jun 2, 2021
@kmilos
Copy link
Contributor Author

kmilos commented Jun 2, 2021

Changed to only fix compressed saving (or when libtiff writer is forced), as those cannot be read otherwise.

Uncompressed internal writer still uses a single strip (updating the strip offsets still TODO), as those files can be read when #5517 is merged (but also only if libtiff reader is forced).

@kmilos kmilos marked this pull request as ready for review June 2, 2021 11:07
@kmilos kmilos force-pushed the fix_tiff_rowsperstrip branch 2 times, most recently from 03e4d2e to 8b82986 Compare June 3, 2021 13:13
@hugovk hugovk merged commit 861a031 into python-pillow:master Jun 30, 2021
@radarhere radarhere changed the title Limit TIFF strip size when saving with libtiff Limit TIFF strip size when saving with LibTIFF Jun 30, 2021
@kmilos kmilos deleted the fix_tiff_rowsperstrip branch June 30, 2021 15:07
@radarhere radarhere mentioned this pull request Aug 27, 2021
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants