geotiff: eager BigTIFF auto-detection uses exact IFD overhead#1906
Merged
Conversation
Replace the fixed 1 KB-per-IFD fudge in ``_assemble_tiff`` with ``_compute_classic_ifd_overhead``, the same helper the streaming writer uses. The previous estimate under-promoted to BigTIFF near the 4 GiB boundary when ``gdal_metadata_xml`` or ``extra_tags`` pushed the overflow heap past 1 KB. Closes #1905.
Contributor
There was a problem hiding this comment.
Pull request overview
Replaces the eager writer's fixed 1 KB-per-IFD fudge overhead with an exact computation via _compute_classic_ifd_overhead, the same helper used by the streaming writer. This eliminates a late struct.error failure mode near the 4 GiB classic-TIFF boundary when large gdal_metadata_xml or extra_tags push the overflow heap past 1 KB, and harmonizes BigTIFF promotion across eager and streaming paths.
Changes:
- In
_assemble_tiff, replace thenum_levels * (2 + 12 * max_tags_per_ifd + 4 + 1024)estimate withsum(_compute_classic_ifd_overhead(tags) for tags in ifd_specs). - Add regression tests covering overhead exactness, strip-offset accounting, promotion under monkey-patched overhead, classic-fits sanity, and round-trip with large
gdal_metadata_xml.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| xrspatial/geotiff/_writer.py | Use exact IFD overhead from _compute_classic_ifd_overhead for BigTIFF auto-detection. |
| xrspatial/geotiff/tests/test_eager_bigtiff_overhead_exact_1905.py | New tests verifying exact overhead and BigTIFF promotion behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
num_levels * (2 + 12 * max_tags_per_ifd + 4 + 1024)estimate in_assemble_tiffwithsum(_compute_classic_ifd_overhead(tags) for tags in ifd_specs). The helper already exists and is what the streaming writer uses (geotiff: streaming dask writer picks classic TIFF too late near the 4 GB boundary #1785, geotiff: account for IFD overhead when picking BigTIFF in streaming writer (#1785) #1787); it builds the IFD and returns the exact bytes the heap will occupy.gdal_metadata_xmlorextra_tagspushed the actual overflow heap past it, so the writer would pick classic and then fail late during offset packing.Closes #1905.
Test plan
pytest xrspatial/geotiff/tests/test_eager_bigtiff_overhead_exact_1905.py— 7 new tests pass (estimate exactness, overflow heap accounting, BigTIFF promotion path, classic-fits-comfortably path)pytest xrspatial/geotiff/tests/ -k "writer or to_geotiff or bigtiff or streaming or assemble"— 453 passed, no regressionsxrspatial/geotiff/tests/suite passes (2869 tests; 2 pre-existing failures on main are unrelated)