Skip to content

Preserve EXIF subdirectories in compressed TIFFs - #10470

Open
harshitdeora wants to merge 4 commits into
python-pillow:mainfrom
harshitdeora:fix/libtiff-exif-subifd
Open

harshitdeora wants to merge 4 commits into
python-pillow:mainfrom
harshitdeora:fix/libtiff-exif-subifd

Conversation

@harshitdeora

Copy link
Copy Markdown

Addresses the compressed TIFF case in #10460. The uncompressed case is tracked separately in #10461.

Saving a JPEG's EXIF metadata into a compressed TIFF passes a subdirectory dictionary to LibTIFF's offset field and raises RuntimeError: Error setting from dictionary. Serialize the subdirectories with Pillow's existing IFD writer, place them after the ClassicTIFF header, and give LibTIFF their destination offsets. For multipage TIFFs the main directory pointer is rebased when the page is appended.

The regression covers file paths and memory buffers, LZW and Adobe Deflate, and single and multiple pages. It checks the pixels and verifies that EXIF, GPS, and the nested interoperability directory can be read back.

Validation on Linux / CPython 3.12

  • All 8 regression cases fail on upstream 4d01b943 and pass on this branch with LibTIFF 4.7.2.
  • Related suites pass with LibTIFF 4.7.2 (355 passed, 6 skipped) and 4.5.1 (356 passed, 5 skipped).
  • Full suite with LibTIFF 4.7.2: 5,526 passed, 424 skipped, 3 xfailed. Self-test: 59 passed. Changed-file formatting, lint, and diff checks passed.
  • Windows reproduced the original error on Pillow 13.0.0. The patched native build was tested on Linux.

@radarhere

Copy link
Copy Markdown
Member

I have merged #10461, in case you would like to do anything based on that.

I will also point out that there is a Lint failure at the moment.

@harshitdeora

Copy link
Copy Markdown
Author

Fixed the mypy failure in d97cd48 (rebased and pushed as c8e626a). The LibTIFF serializer now uses distinct names for the new subdirectory payload and value, and the regression fixture has explicit types. Validation after the rebase: Tests/test_file_libtiff.py — 135 passed, 1 skipped; targeted mypy on both changed files passes; Ruff, Black, and git diff --check pass.

@nehachinnasani23

Copy link
Copy Markdown

Fixed the mypy failure in d97cd48 (rebased and pushed as c8e626a). The LibTIFF serializer now uses distinct names for the new subdirectory payload and value, and the regression fixture has explicit types. Validation after the rebase: Tests/test_file_libtiff.py — 135 passed, 1 skipped; targeted mypy on both changed files passes; Ruff, Black, and git diff --check pass.

Hi @harshitdeora, @radarhere suggested combining my PR #10560 with yours because they address the same compressed-TIFF metadata issue. Would you be open to incorporating the additional regression tests and any missing edge-case handling from my PR? I can test them against your branch and share a focused patch.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants