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
Conversation
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: |
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. |
820997e
to
4b5488c
Compare
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). |
03e4d2e
to
8b82986
Compare
8b82986
to
100299a
Compare
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.