Skip to content

Commit

Permalink
Internal libtiff: resync to suppress warnings about unknowns tags / h…
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Oct 30, 2024
1 parent 38fb9e9 commit dc207a2
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
34 changes: 22 additions & 12 deletions frmts/gtiff/libtiff/tif_dirread.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions frmts/gtiff/libtiff/tif_open.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions frmts/gtiff/libtiff/tiffio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions frmts/gtiff/libtiff/tiffiop.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 */
Expand Down

0 comments on commit dc207a2

Please sign in to comment.