Skip to content

Suppress spurious libtiff warnings when decoding GeoTIFF files#52

Open
shreyaskommuri wants to merge 2 commits intoNVIDIA:mainfrom
shreyaskommuri:fix/geotiff-libtiff-warnings
Open

Suppress spurious libtiff warnings when decoding GeoTIFF files#52
shreyaskommuri wants to merge 2 commits intoNVIDIA:mainfrom
shreyaskommuri:fix/geotiff-libtiff-warnings

Conversation

@shreyaskommuri
Copy link
Copy Markdown

Summary

GeoTIFF embeds geographic metadata using tags that libtiff does not recognise natively (ModelPixelScale 33550, ModelTiepoint 33922, ModelTransformation 34264, GeoKeyDirectory 34735, GeoDoubleParams 34736, GeoAsciiParams 34737, GDAL_METADATA 42112, GDAL_NODATA 42113). libtiff emits TIFFReadDirectory: Warning, Unknown field with tag X encountered for each one on every decode. The image data is decoded correctly; only the warnings pollute stderr.

  • Install a custom TIFFWarningHandler (SuppressGeoTIFFTagWarnings) in extensions/libtiff/error_handling.h that silently drops warnings for the eight known GeoTIFF/GDAL tags and forwards all other libtiff warnings to stderr unchanged. Guards against a null module argument (permitted by the libtiff contract).
  • Call InstallGeoTIFFWarningFilter() — which uses std::call_once with a function-local static in an inline function, so the once_flag is shared across all translation units and the handler is registered exactly once per process — from libtiffExtensionCreate in libtiff_ext.cpp.
  • Add _create_geotiff test helper in test/python/test_decode_tiff.py that builds a valid 4×4 GeoTIFF from scratch using only struct (no third-party dependency), embedding all eight suppressed tags. Add test_decode_tiff_geotiff that decodes the synthetic file with CPU_ONLY and default backends and asserts correct pixel values.

Related

Ported from NVIDIA/DALI#6336 at the request of @jantonguirao — the fix belongs at the libtiff layer in nvImageCodec rather than in DALI's image decoder.

Closes NVIDIA/DALI#6114 (via nvImageCodec bump in DALI).

Type of Change

  • Bug fix

Test plan

  • _create_geotiff helper produces a TIFF-spec-valid file (all 8 GeoTIFF tags, correct inline/offset layout, pixel data intact)
  • test_decode_tiff_geotiff parametrized over CPU_ONLY and default backends
  • Run pytest test/python/test_decode_tiff.py::test_decode_tiff_geotiff in CI

AI Disclosure

  • AI-assisted — tool: Claude Code

Signed-off-by: shreyaskommuri shreyaskommuri@gmail.com

GeoTIFF embeds geographic metadata using tags that libtiff does not
recognise natively (ModelPixelScale 33550, ModelTiepoint 33922,
ModelTransformation 34264, GeoKeyDirectory 34735, GeoDoubleParams 34736,
GeoAsciiParams 34737, GDAL_METADATA 42112, GDAL_NODATA 42113).
libtiff emits "Unknown field with tag X encountered" warnings for each
one. The image data is decoded correctly; only the warnings pollute stderr.

Install a custom TIFFWarningHandler (SuppressGeoTIFFTagWarnings) in
error_handling.h that silently drops warnings for these eight known tags
and forwards all other libtiff warnings to stderr unchanged. Call
InstallGeoTIFFWarningFilter() — which uses std::call_once so the handler
is registered exactly once per process — from libtiffExtensionCreate in
libtiff_ext.cpp, which is the natural entry point for the libtiff extension.

Add test_decode_tiff_geotiff to test/python/test_decode_tiff.py. The test
helper _create_geotiff builds a valid TIFF from scratch using only struct
(no third-party dependency), embedding all eight suppressed tags. The test
decodes the synthetic file with CPU_ONLY and default backends and asserts
correct pixel values.

Fixes: NVIDIA/DALI#6114
Signed-off-by: shreyaskommuri <shreyaskommuri@gmail.com>
b"0\x00" is 2 bytes — since count*typesize (2) <= 4, TIFF requires the
value to be stored inline in the IFD entry, not as a file offset. The
IFD entry was incorrectly treating a file offset as the value. Use
b"-9999\x00" (6 bytes) so the offset is spec-valid.

Signed-off-by: shreyaskommuri <shreyaskommuri@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for GeoTIFF images

1 participant