From dc207a2cd9d68323b37aab18684a5e1f4c6badcf Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Wed, 30 Oct 2024 19:18:45 +0100 Subject: [PATCH] Internal libtiff: resync to suppress warnings about unknowns tags / https://gitlab.com/libtiff/libtiff/-/merge_requests/463 --- frmts/gtiff/libtiff/tif_dirread.c | 34 ++++++++++++++++++++----------- frmts/gtiff/libtiff/tif_open.c | 10 +++++++++ frmts/gtiff/libtiff/tiffio.h | 3 +++ frmts/gtiff/libtiff/tiffiop.h | 2 ++ 4 files changed, 37 insertions(+), 12 deletions(-) diff --git a/frmts/gtiff/libtiff/tif_dirread.c b/frmts/gtiff/libtiff/tif_dirread.c index 3d94ea7d4f37..76fd4dda7ebc 100644 --- a/frmts/gtiff/libtiff/tif_dirread.c +++ b/frmts/gtiff/libtiff/tif_dirread.c @@ -4403,10 +4403,13 @@ int TIFFReadDirectory(TIFF *tif) TIFFReadDirectoryFindFieldInfo(tif, dp->tdir_tag, &fii); if (fii == FAILED_FII) { - TIFFWarningExtR(tif, module, - "Unknown field with tag %" PRIu16 " (0x%" PRIx16 - ") encountered", - dp->tdir_tag, dp->tdir_tag); + if (tif->tif_warn_about_unknown_tags) + { + TIFFWarningExtR(tif, module, + "Unknown field with tag %" PRIu16 + " (0x%" PRIx16 ") encountered", + dp->tdir_tag, dp->tdir_tag); + } /* the following knowingly leaks the anonymous field structure */ const TIFFField *fld = _TIFFCreateAnonField( @@ -5344,18 +5347,25 @@ int TIFFReadCustomDirectory(TIFF *tif, toff_t diroff, TIFFReadDirectoryFindFieldInfo(tif, dp->tdir_tag, &fii); if (fii == FAILED_FII) { - TIFFWarningExtR(tif, module, - "Unknown field with tag %" PRIu16 " (0x%" PRIx16 - ") encountered", - dp->tdir_tag, dp->tdir_tag); + if (tif->tif_warn_about_unknown_tags) + { + TIFFWarningExtR(tif, module, + "Unknown field with tag %" PRIu16 " (0x%" PRIx16 + ") encountered", + dp->tdir_tag, dp->tdir_tag); + } const TIFFField *fld = _TIFFCreateAnonField( tif, dp->tdir_tag, (TIFFDataType)dp->tdir_type); if (fld == NULL || !_TIFFMergeFields(tif, fld, 1)) { - TIFFWarningExtR(tif, module, - "Registering anonymous field with tag %" PRIu16 - " (0x%" PRIx16 ") failed", - dp->tdir_tag, dp->tdir_tag); + if (tif->tif_warn_about_unknown_tags) + { + TIFFWarningExtR( + tif, module, + "Registering anonymous field with tag %" PRIu16 + " (0x%" PRIx16 ") failed", + dp->tdir_tag, dp->tdir_tag); + } dp->tdir_ignore = TRUE; } else diff --git a/frmts/gtiff/libtiff/tif_open.c b/frmts/gtiff/libtiff/tif_open.c index 59a07bee0232..3c1eb6babdbc 100644 --- a/frmts/gtiff/libtiff/tif_open.c +++ b/frmts/gtiff/libtiff/tif_open.c @@ -109,6 +109,15 @@ void TIFFOpenOptionsSetMaxCumulatedMemAlloc(TIFFOpenOptions *opts, opts->max_cumulated_mem_alloc = max_cumulated_mem_alloc; } +/** Whether a warning should be emitted when encoutering a unknown tag. + * Default is FALSE since libtiff 4.7.1 + */ +void TIFFOpenOptionsSetWarnAboutUnknownTags(TIFFOpenOptions *opts, + int warn_about_unknown_tags) +{ + opts->warn_about_unknown_tags = warn_about_unknown_tags; +} + void TIFFOpenOptionsSetErrorHandlerExtR(TIFFOpenOptions *opts, TIFFErrorHandlerExtR handler, void *errorhandler_user_data) @@ -386,6 +395,7 @@ TIFF *TIFFClientOpenExt(const char *name, const char *mode, tif->tif_warnhandler_user_data = opts->warnhandler_user_data; tif->tif_max_single_mem_alloc = opts->max_single_mem_alloc; tif->tif_max_cumulated_mem_alloc = opts->max_cumulated_mem_alloc; + tif->tif_warn_about_unknown_tags = opts->warn_about_unknown_tags; } if (!readproc || !writeproc || !seekproc || !closeproc || !sizeproc) diff --git a/frmts/gtiff/libtiff/tiffio.h b/frmts/gtiff/libtiff/tiffio.h index 225f3c1bfeab..0034fe85fd09 100644 --- a/frmts/gtiff/libtiff/tiffio.h +++ b/frmts/gtiff/libtiff/tiffio.h @@ -508,6 +508,9 @@ extern int TIFFReadRGBAImageOriented(TIFF *, uint32_t, uint32_t, uint32_t *, TIFFOpenOptionsSetMaxCumulatedMemAlloc(TIFFOpenOptions *opts, tmsize_t max_cumulated_mem_alloc); extern void + TIFFOpenOptionsSetWarnAboutUnknownTags(TIFFOpenOptions *opts, + int warn_about_unknown_tags); + extern void TIFFOpenOptionsSetErrorHandlerExtR(TIFFOpenOptions *opts, TIFFErrorHandlerExtR handler, void *errorhandler_user_data); diff --git a/frmts/gtiff/libtiff/tiffiop.h b/frmts/gtiff/libtiff/tiffiop.h index c4348206df56..90986ee441bc 100644 --- a/frmts/gtiff/libtiff/tiffiop.h +++ b/frmts/gtiff/libtiff/tiffiop.h @@ -258,6 +258,7 @@ struct tiff tmsize_t tif_max_single_mem_alloc; /* in bytes. 0 for unlimited */ tmsize_t tif_max_cumulated_mem_alloc; /* in bytes. 0 for unlimited */ tmsize_t tif_cur_cumulated_mem_alloc; /* in bytes */ + int tif_warn_about_unknown_tags; }; struct TIFFOpenOptions @@ -268,6 +269,7 @@ struct TIFFOpenOptions void *warnhandler_user_data; /* may be NULL */ tmsize_t max_single_mem_alloc; /* in bytes. 0 for unlimited */ tmsize_t max_cumulated_mem_alloc; /* in bytes. 0 for unlimited */ + int warn_about_unknown_tags; }; #define isPseudoTag(t) (t > 0xffff) /* is tag value normal or pseudo */