From 46f6411b2c86424b6bd0368abee13b8937085c3f Mon Sep 17 00:00:00 2001 From: Andrey Kiselev Date: Sat, 7 Apr 2007 15:14:30 +0000 Subject: [PATCH] Finally fix bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1274 by introducing _TIFFMergeFieldInfo() returning integer error status instead of void in case of problems with field merging (e.g., if the field with such a tag already registered). TIFFMergeFieldInfo() in public API remains void. Use _TIFFMergeFieldInfo() everywhere and check returned value. --- libtiff/tif_dir.h | 4 +- libtiff/tif_dirinfo.c | 116 +++++++++++++++++++++++------------------ libtiff/tif_dirread.c | 42 ++++++++++----- libtiff/tif_fax3.c | 35 ++++++++++--- libtiff/tif_jbig.c | 19 ++++--- libtiff/tif_jpeg.c | 20 ++++--- libtiff/tif_luv.c | 18 +++++-- libtiff/tif_ojpeg.c | 14 ++++- libtiff/tif_pixarlog.c | 18 +++++-- libtiff/tif_predict.c | 17 ++++-- libtiff/tif_zip.c | 19 +++++-- 11 files changed, 215 insertions(+), 107 deletions(-) diff --git a/libtiff/tif_dir.h b/libtiff/tif_dir.h index 53ce7843..69366d00 100644 --- a/libtiff/tif_dir.h +++ b/libtiff/tif_dir.h @@ -1,4 +1,4 @@ -/* $Id: tif_dir.h,v 1.35 2007-04-04 04:16:07 joris Exp $ */ +/* $Id: tif_dir.h,v 1.36 2007-04-07 15:14:30 dron Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -180,6 +180,7 @@ extern "C" { extern const TIFFFieldInfo *_TIFFGetFieldInfo(size_t *); extern const TIFFFieldInfo *_TIFFGetExifFieldInfo(size_t *); extern void _TIFFSetupFieldInfo(TIFF* tif, const TIFFFieldInfo unfo[], uint32 n); +extern int _TIFFMergeFieldInfo(TIFF*, const TIFFFieldInfo[], uint32); extern void _TIFFPrintFieldInfo(TIFF*, FILE*); extern TIFFDataType _TIFFSampleToTagType(TIFF*); extern const TIFFFieldInfo* _TIFFFindOrRegisterFieldInfo(TIFF *tif, uint32 tag, @@ -187,7 +188,6 @@ extern const TIFFFieldInfo* _TIFFFindOrRegisterFieldInfo(TIFF *tif, uint32 tag, extern TIFFFieldInfo* _TIFFCreateAnonFieldInfo(TIFF *tif, uint32 tag, TIFFDataType dt); -#define _TIFFMergeFieldInfo TIFFMergeFieldInfo #define _TIFFFindFieldInfo TIFFFindFieldInfo #define _TIFFFindFieldInfoByName TIFFFindFieldInfoByName #define _TIFFFieldWithTag TIFFFieldWithTag diff --git a/libtiff/tif_dirinfo.c b/libtiff/tif_dirinfo.c index c40e01d0..095e85c2 100644 --- a/libtiff/tif_dirinfo.c +++ b/libtiff/tif_dirinfo.c @@ -1,4 +1,4 @@ -/* $Id: tif_dirinfo.c,v 1.70 2007-04-04 04:16:07 joris Exp $ */ +/* $Id: tif_dirinfo.c,v 1.71 2007-04-07 15:14:30 dron Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -574,7 +574,11 @@ _TIFFSetupFieldInfo(TIFF* tif, const TIFFFieldInfo info[], uint32 n) _TIFFfree(tif->tif_fieldinfo); tif->tif_nfields = 0; } - _TIFFMergeFieldInfo(tif, info, n); + if (!_TIFFMergeFieldInfo(tif, info, n)) + { + TIFFErrorExt(tif->tif_clientdata, "_TIFFSetupFieldInfo", + "Setting up field info failed"); + } } static int @@ -584,9 +588,10 @@ tagCompare(const void* a, const void* b) const TIFFFieldInfo* tb = *(const TIFFFieldInfo**) b; /* NB: be careful of return values for 16-bit platforms */ if (ta->field_tag != tb->field_tag) - return (ta->field_tag < tb->field_tag ? -1 : 1); + return (int)ta->field_tag - (int)tb->field_tag; else - return ((int)tb->field_type - (int)ta->field_type); + return (ta->field_type == TIFF_ANY) ? + 0 : ((int)tb->field_type - (int)ta->field_type); } static int @@ -594,22 +599,49 @@ tagNameCompare(const void* a, const void* b) { const TIFFFieldInfo* ta = *(const TIFFFieldInfo**) a; const TIFFFieldInfo* tb = *(const TIFFFieldInfo**) b; + int ret = strcmp(ta->field_name, tb->field_name); - return strcmp(ta->field_name, tb->field_name); + if (ret) + return ret; + else + return (ta->field_type == TIFF_ANY) ? + 0 : ((int)tb->field_type - (int)ta->field_type); } void +TIFFMergeFieldInfo(TIFF* tif, const TIFFFieldInfo info[], uint32 n) +{ + if (_TIFFMergeFieldInfo(tif, info, n) < 0) + { + TIFFErrorExt(tif->tif_clientdata, "TIFFMergeFieldInfo", + "Merging block of %d fields failed", n); + } +} + +int _TIFFMergeFieldInfo(TIFF* tif, const TIFFFieldInfo info[], uint32 n) { TIFFFieldInfo** tp; uint32 i; + for (i = 0; i < n; i++) { + const TIFFFieldInfo *fip = + _TIFFFindFieldInfo(tif, info[i].field_tag, TIFF_ANY); + if (fip) { + TIFFErrorExt(tif->tif_clientdata, "_TIFFMergeFieldInfo", + "Field with tag %lu is already registered as \"%s\"", + (unsigned int) info[i].field_tag, + fip->field_name); + return 0; + } + } + tif->tif_foundfield = NULL; if (tif->tif_nfields > 0) { tif->tif_fieldinfo = (TIFFFieldInfo**) _TIFFrealloc(tif->tif_fieldinfo, - (tif->tif_nfields+n) * sizeof (TIFFFieldInfo*)); + (tif->tif_nfields + n) * sizeof (TIFFFieldInfo*)); } else { tif->tif_fieldinfo = (TIFFFieldInfo**) _TIFFmalloc(n * sizeof (TIFFFieldInfo*)); @@ -622,6 +654,8 @@ _TIFFMergeFieldInfo(TIFF* tif, const TIFFFieldInfo info[], uint32 n) /* Sort the field info by tag number */ qsort(tif->tif_fieldinfo, tif->tif_nfields += n, sizeof (TIFFFieldInfo*), tagCompare); + + return n; } void @@ -743,69 +777,46 @@ _TIFFSampleToTagType(TIFF* tif) const TIFFFieldInfo* _TIFFFindFieldInfo(TIFF* tif, uint32 tag, TIFFDataType dt) { - int i, n; - if (tif->tif_foundfield && tif->tif_foundfield->field_tag == tag && (dt == TIFF_ANY || dt == tif->tif_foundfield->field_type)) return tif->tif_foundfield; /* NB: use sorted search (e.g. binary search) */ - if(dt != TIFF_ANY) { - TIFFFieldInfo key = {0, 0, 0, TIFF_NOTYPE, 0, 0, 0, 0}; - TIFFFieldInfo* pkey = &key; - const TIFFFieldInfo **ret; + TIFFFieldInfo key = {0, 0, 0, TIFF_NOTYPE, 0, 0, 0, 0}; + TIFFFieldInfo* pkey = &key; + const TIFFFieldInfo **ret; - key.field_tag = tag; - key.field_type = dt; + key.field_tag = tag; + key.field_type = dt; - ret = (const TIFFFieldInfo **) bsearch(&pkey, - tif->tif_fieldinfo, - tif->tif_nfields, - sizeof(TIFFFieldInfo *), - tagCompare); - return ret ? *ret : NULL; - } else for (i = 0, n = tif->tif_nfields; i < n; i++) { - const TIFFFieldInfo* fip = tif->tif_fieldinfo[i]; - if (fip->field_tag == tag && - (dt == TIFF_ANY || fip->field_type == dt)) - return (tif->tif_foundfield = fip); - } - return (const TIFFFieldInfo *)0; + ret = (const TIFFFieldInfo **) bsearch(&pkey, + tif->tif_fieldinfo, + tif->tif_nfields, + sizeof(TIFFFieldInfo *), + tagCompare); + return tif->tif_foundfield = (ret ? *ret : NULL); } const TIFFFieldInfo* _TIFFFindFieldInfoByName(TIFF* tif, const char *field_name, TIFFDataType dt) { - uint32 i, n; - if (tif->tif_foundfield && streq(tif->tif_foundfield->field_name, field_name) && (dt == TIFF_ANY || dt == tif->tif_foundfield->field_type)) return (tif->tif_foundfield); /* NB: use sorted search (e.g. binary search) */ - if(dt != TIFF_ANY) { - TIFFFieldInfo key = {0, 0, 0, TIFF_NOTYPE, 0, 0, 0, 0}; - TIFFFieldInfo* pkey = &key; - const TIFFFieldInfo **ret; - size_t nfields; + TIFFFieldInfo key = {0, 0, 0, TIFF_NOTYPE, 0, 0, 0, 0}; + TIFFFieldInfo* pkey = &key; + const TIFFFieldInfo **ret; - key.field_name = (char *)field_name; - key.field_type = dt; - nfields = tif->tif_nfields; + key.field_name = (char *)field_name; + key.field_type = dt; - ret = (const TIFFFieldInfo **) lfind(&pkey, - tif->tif_fieldinfo, - &nfields, - sizeof(TIFFFieldInfo *), - tagNameCompare); - return (ret) ? (*ret) : NULL; - } else - for (i = 0, n = tif->tif_nfields; i < n; i++) { - const TIFFFieldInfo* fip = tif->tif_fieldinfo[i]; - if (streq(fip->field_name, field_name) && - (dt == TIFF_ANY || fip->field_type == dt)) - return (tif->tif_foundfield = fip); - } - return ((const TIFFFieldInfo *)0); + ret = (const TIFFFieldInfo **) lfind(&pkey, + tif->tif_fieldinfo, + &tif->tif_nfields, + sizeof(TIFFFieldInfo *), + tagNameCompare); + return tif->tif_foundfield = (ret ? *ret : NULL); } const TIFFFieldInfo* @@ -846,7 +857,8 @@ _TIFFFindOrRegisterFieldInfo( TIFF *tif, uint32 tag, TIFFDataType dt ) if( fld == NULL ) { fld = _TIFFCreateAnonFieldInfo( tif, tag, dt ); - _TIFFMergeFieldInfo( tif, fld, 1 ); + if (!_TIFFMergeFieldInfo(tif, fld, 1)) + return NULL; } return fld; diff --git a/libtiff/tif_dirread.c b/libtiff/tif_dirread.c index a09991c9..7f8f6881 100644 --- a/libtiff/tif_dirread.c +++ b/libtiff/tif_dirread.c @@ -1,4 +1,4 @@ -/* $Id: tif_dirread.c,v 1.104 2007-04-04 04:16:07 joris Exp $ */ +/* $Id: tif_dirread.c,v 1.105 2007-04-07 15:14:30 dron Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -1791,12 +1791,21 @@ TIFFReadDirectory(TIFF* tif) TIFFReadDirectoryFindFieldInfo(tif,dp->tdir_tag,&fii); if (fii==(uint32)(-1)) { - TIFFWarningExt(tif->tif_clientdata,module, - "Unknown field with tag %d (0x%x) encountered", - dp->tdir_tag,dp->tdir_tag); - TIFFMergeFieldInfo(tif, - _TIFFCreateAnonFieldInfo(tif,dp->tdir_tag, - (TIFFDataType)dp->tdir_type),1); + TIFFWarningExt(tif->tif_clientdata, module, + "Unknown field with tag %d (0x%x) encountered", + dp->tdir_tag,dp->tdir_tag); + if (!_TIFFMergeFieldInfo(tif, + _TIFFCreateAnonFieldInfo(tif, + dp->tdir_tag, + (TIFFDataType) dp->tdir_type), + 1)) { + TIFFErrorExt(tif->tif_clientdata, + module, + "Registering anonymous field with tag %d (0x%x) failed", + dp->tdir_tag, + dp->tdir_tag); + goto ignore; + } TIFFReadDirectoryFindFieldInfo(tif,dp->tdir_tag,&fii); assert(fii!=(uint32)(-1)); } @@ -2397,12 +2406,19 @@ TIFFReadCustomDirectory(TIFF* tif, uint64_new diroff, const TIFFFieldInfo info[] TIFFReadDirectoryFindFieldInfo(tif,dp->tdir_tag,&fii); if (fii==0xFFFF) { - TIFFWarningExt(tif->tif_clientdata,module, - "Unknown field with tag %d (0x%x) encountered", - dp->tdir_tag,dp->tdir_tag); - TIFFMergeFieldInfo(tif, - _TIFFCreateAnonFieldInfo(tif,dp->tdir_tag, - (TIFFDataType)dp->tdir_type),1); + TIFFWarningExt(tif->tif_clientdata, module, + "Unknown field with tag %d (0x%x) encountered", + dp->tdir_tag, dp->tdir_tag); + if (!_TIFFMergeFieldInfo(tif, + _TIFFCreateAnonFieldInfo(tif, + dp->tdir_tag, + (TIFFDataType) dp->tdir_type), + 1)) { + TIFFErrorExt(tif->tif_clientdata, module, + "Registering anonymous field with tag %d (0x%x) failed", + dp->tdir_tag, dp->tdir_tag); + goto ignore; + } TIFFReadDirectoryFindFieldInfo(tif,dp->tdir_tag,&fii); assert(fii!=0xFFFF); } diff --git a/libtiff/tif_fax3.c b/libtiff/tif_fax3.c index ee424906..0b4e9908 100644 --- a/libtiff/tif_fax3.c +++ b/libtiff/tif_fax3.c @@ -1,4 +1,4 @@ -/* $Id: tif_fax3.c,v 1.49 2007-04-05 16:15:10 joris Exp $ */ +/* $Id: tif_fax3.c,v 1.50 2007-04-07 15:14:30 dron Exp $ */ /* * Copyright (c) 1990-1997 Sam Leffler @@ -1320,6 +1320,15 @@ InitCCITTFax3(TIFF* tif) static const char module[] = "InitCCITTFax3"; Fax3BaseState* sp; + /* + * Merge codec-specific tag information. + */ + if (!_TIFFMergeFieldInfo(tif, faxFieldInfo, N(faxFieldInfo))) { + TIFFErrorExt(tif->tif_clientdata, "InitCCITTFax3", + "Merging common CCITT Fax codec-specific tags failed"); + return 0; + } + /* * Allocate state block so tag methods have storage to record values. */ @@ -1336,10 +1345,8 @@ InitCCITTFax3(TIFF* tif) sp->rw_mode = tif->tif_mode; /* - * Merge codec-specific tag information and - * override parent get/set field methods. + * Override parent get/set field methods. */ - _TIFFMergeFieldInfo(tif, faxFieldInfo, N(faxFieldInfo)); sp->vgetparent = tif->tif_tagmethods.vgetfield; tif->tif_tagmethods.vgetfield = Fax3VGetField; /* hook for codec tags */ sp->vsetparent = tif->tif_tagmethods.vsetfield; @@ -1382,14 +1389,21 @@ TIFFInitCCITTFax3(TIFF* tif, int scheme) { (void) scheme; if (InitCCITTFax3(tif)) { - _TIFFMergeFieldInfo(tif, fax3FieldInfo, N(fax3FieldInfo)); + /* + * Merge codec-specific tag information. + */ + if (!_TIFFMergeFieldInfo(tif, fax3FieldInfo, N(fax3FieldInfo))) { + TIFFErrorExt(tif->tif_clientdata, "TIFFInitCCITTFax3", + "Merging CCITT Fax 3 codec-specific tags failed"); + return 0; + } /* * The default format is Class/F-style w/o RTC. */ return TIFFSetField(tif, TIFFTAG_FAXMODE, FAXMODE_CLASSF); } else - return (0); + return 01; } /* @@ -1492,7 +1506,14 @@ TIFFInitCCITTFax4(TIFF* tif, int scheme) { (void) scheme; if (InitCCITTFax3(tif)) { /* reuse G3 support */ - _TIFFMergeFieldInfo(tif, fax4FieldInfo, N(fax4FieldInfo)); + /* + * Merge codec-specific tag information. + */ + if (!_TIFFMergeFieldInfo(tif, fax4FieldInfo, N(fax4FieldInfo))) { + TIFFErrorExt(tif->tif_clientdata, "TIFFInitCCITTFax4", + "Merging CCITT Fax 4 codec-specific tags failed"); + return 0; + } tif->tif_decoderow = Fax4Decode; tif->tif_decodestrip = Fax4Decode; diff --git a/libtiff/tif_jbig.c b/libtiff/tif_jbig.c index 03d9177d..2078c15b 100644 --- a/libtiff/tif_jbig.c +++ b/libtiff/tif_jbig.c @@ -1,4 +1,4 @@ -/* $Id: tif_jbig.c,v 1.4 2007-03-31 01:41:11 joris Exp $ */ +/* $Id: tif_jbig.c,v 1.5 2007-04-07 15:14:30 dron Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -49,7 +49,6 @@ typedef struct } JBIGState; #define GetJBIGState(tif) ((JBIGState*)(tif)->tif_data) -#define N(a) (sizeof (a) / sizeof (a[0])) #define FIELD_RECVPARAMS (FIELD_CODEC+0) #define FIELD_SUBADDRESS (FIELD_CODEC+1) @@ -308,6 +307,16 @@ int TIFFInitJBIG(TIFF* tif, int scheme) assert(scheme == COMPRESSION_JBIG); + /* + * Merge codec-specific tag information. + */ + if (!_TIFFMergeFieldInfo(tif, jbigFieldInfo, + TIFFArrayCount(jbigFieldInfo))) { + TIFFErrorExt(tif->tif_clientdata, "TIFFInitJBIG", + "Merging JBIG codec-specific tags failed"); + return 0; + } + /* Allocate memory for the JBIGState structure.*/ tif->tif_data = (tdata_t)_TIFFmalloc(sizeof(JBIGState)); if (tif->tif_data == NULL) @@ -325,14 +334,10 @@ int TIFFInitJBIG(TIFF* tif, int scheme) codec->recvtime = 0; /* - * Register codec private fields with libtiff and setup function - * pointers. + * Override parent get/set field methods. */ - _TIFFMergeFieldInfo(tif, jbigFieldInfo, N(jbigFieldInfo)); - codec->vgetparent = tif->tif_tagmethods.vgetfield; codec->vsetparent = tif->tif_tagmethods.vsetfield; - tif->tif_tagmethods.vgetfield = JBIGVGetField; tif->tif_tagmethods.vsetfield = JBIGVSetField; tif->tif_tagmethods.printdir = JBIGPrintDir; diff --git a/libtiff/tif_jpeg.c b/libtiff/tif_jpeg.c index 82bafde3..2487bf8e 100644 --- a/libtiff/tif_jpeg.c +++ b/libtiff/tif_jpeg.c @@ -1,4 +1,4 @@ -/* $Id: tif_jpeg.c,v 1.55 2007-04-06 21:04:27 fwarmerdam Exp $ */ +/* $Id: tif_jpeg.c,v 1.56 2007-04-07 15:14:30 dron Exp $ */ /* * Copyright (c) 1994-1997 Sam Leffler @@ -1929,6 +1929,16 @@ TIFFInitJPEG(TIFF* tif, int scheme) assert(scheme == COMPRESSION_JPEG); + /* + * Merge codec-specific tag information. + */ + if (!_TIFFMergeFieldInfo(tif, jpegFieldInfo, N(jpegFieldInfo))) { + TIFFErrorExt(tif->tif_clientdata, + "TIFFInitJPEG", + "Merging JPEG codec-specific tags failed"); + return 0; + } + /* * Allocate state block so tag methods have storage to record values. */ @@ -1937,18 +1947,16 @@ TIFFInitJPEG(TIFF* tif, int scheme) if (tif->tif_data == NULL) { TIFFErrorExt(tif->tif_clientdata, "TIFFInitJPEG", "No space for JPEG state block"); - return (0); + return 0; } - _TIFFmemset( tif->tif_data, 0, sizeof(JPEGState)); + _TIFFmemset(tif->tif_data, 0, sizeof(JPEGState)); sp = JState(tif); sp->tif = tif; /* back link */ /* - * Merge codec-specific tag information and override parent get/set - * field methods. + * Override parent get/set field methods. */ - _TIFFMergeFieldInfo(tif, jpegFieldInfo, N(jpegFieldInfo)); sp->vgetparent = tif->tif_tagmethods.vgetfield; tif->tif_tagmethods.vgetfield = JPEGVGetField; /* hook for codec tags */ sp->vsetparent = tif->tif_tagmethods.vsetfield; diff --git a/libtiff/tif_luv.c b/libtiff/tif_luv.c index ee71e7b4..915fc16a 100644 --- a/libtiff/tif_luv.c +++ b/libtiff/tif_luv.c @@ -1,4 +1,4 @@ -/* $Id: tif_luv.c,v 1.20 2007-03-31 01:41:11 joris Exp $ */ +/* $Id: tif_luv.c,v 1.21 2007-04-07 15:14:30 dron Exp $ */ /* * Copyright (c) 1997 Greg Ward Larson @@ -1560,6 +1560,16 @@ TIFFInitSGILog(TIFF* tif, int scheme) assert(scheme == COMPRESSION_SGILOG24 || scheme == COMPRESSION_SGILOG); + /* + * Merge codec-specific tag information. + */ + if (!_TIFFMergeFieldInfo(tif, LogLuvFieldInfo, + TIFFArrayCount(LogLuvFieldInfo))) { + TIFFErrorExt(tif->tif_clientdata, module, + "Merging SGILog codec-specific tags failed"); + return 0; + } + /* * Allocate state block so tag methods have storage to record values. */ @@ -1587,9 +1597,9 @@ TIFFInitSGILog(TIFF* tif, int scheme) tif->tif_close = LogLuvClose; tif->tif_cleanup = LogLuvCleanup; - /* override SetField so we can handle our private pseudo-tag */ - _TIFFMergeFieldInfo(tif, LogLuvFieldInfo, - TIFFArrayCount(LogLuvFieldInfo)); + /* + * Override parent get/set field methods. + */ sp->vgetparent = tif->tif_tagmethods.vgetfield; tif->tif_tagmethods.vgetfield = LogLuvVGetField; /* hook for codec tags */ sp->vsetparent = tif->tif_tagmethods.vsetfield; diff --git a/libtiff/tif_ojpeg.c b/libtiff/tif_ojpeg.c index df40c708..b93d7aad 100644 --- a/libtiff/tif_ojpeg.c +++ b/libtiff/tif_ojpeg.c @@ -1,4 +1,4 @@ -/* $Id: tif_ojpeg.c,v 1.26 2007-03-31 01:41:11 joris Exp $ */ +/* $Id: tif_ojpeg.c,v 1.27 2007-04-07 15:14:30 dron Exp $ */ /* WARNING: The type of JPEG encapsulation defined by the TIFF Version 6.0 specification is now totally obsolete and deprecated for new applications and @@ -393,7 +393,18 @@ TIFFInitOJPEG(TIFF* tif, int scheme) { static const char module[]="TIFFInitOJPEG"; OJPEGState* sp; + assert(scheme==COMPRESSION_OJPEG); + + /* + * Merge codec-specific tag information. + */ + if (!_TIFFMergeFieldInfo(tif,ojpeg_field_info,FIELD_OJPEG_COUNT)) { + TIFFErrorExt(tif->tif_clientdata, module, + "Merging Old JPEG codec-specific tags failed"); + return 0; + } + /* state block */ sp=_TIFFmalloc(sizeof(OJPEGState)); if (sp==NULL) @@ -423,7 +434,6 @@ TIFFInitOJPEG(TIFF* tif, int scheme) tif->tif_cleanup=OJPEGCleanup; tif->tif_data=(tidata_t)sp; /* tif tag methods */ - _TIFFMergeFieldInfo(tif,ojpeg_field_info,FIELD_OJPEG_COUNT); sp->vgetparent=tif->tif_tagmethods.vgetfield; tif->tif_tagmethods.vgetfield=OJPEGVGetField; sp->vsetparent=tif->tif_tagmethods.vsetfield; diff --git a/libtiff/tif_pixarlog.c b/libtiff/tif_pixarlog.c index e682be87..1497c046 100644 --- a/libtiff/tif_pixarlog.c +++ b/libtiff/tif_pixarlog.c @@ -1,4 +1,4 @@ -/* $Id: tif_pixarlog.c,v 1.18 2007-03-31 01:41:11 joris Exp $ */ +/* $Id: tif_pixarlog.c,v 1.19 2007-04-07 15:14:31 dron Exp $ */ /* * Copyright (c) 1996-1997 Sam Leffler @@ -593,7 +593,6 @@ PixarLogMakeTables(PixarLogState *sp) static int PixarLogEncode(TIFF*, tidata_t, tsize_t, uint16); static int PixarLogDecode(TIFF*, tidata_t, tsize_t, uint16); -#define N(a) (sizeof(a)/sizeof(a[0])) #define PIXARLOGDATAFMT_UNKNOWN -1 static int @@ -1290,10 +1289,22 @@ static const TIFFFieldInfo pixarlogFieldInfo[] = { int TIFFInitPixarLog(TIFF* tif, int scheme) { + const char module[] = "TIFFInitPixarLog"; + PixarLogState* sp; assert(scheme == COMPRESSION_PIXARLOG); + /* + * Merge codec-specific tag information. + */ + if (!_TIFFMergeFieldInfo(tif, pixarlogFieldInfo, + TIFFArrayCount(pixarlogFieldInfo))) { + TIFFErrorExt(tif->tif_clientdata, module, + "Merging PixarLog codec-specific tags failed"); + return 0; + } + /* * Allocate state block so tag methods have storage to record values. */ @@ -1323,7 +1334,6 @@ TIFFInitPixarLog(TIFF* tif, int scheme) tif->tif_cleanup = PixarLogCleanup; /* Override SetField so we can handle our private pseudo-tag */ - _TIFFMergeFieldInfo(tif, pixarlogFieldInfo, N(pixarlogFieldInfo)); sp->vgetparent = tif->tif_tagmethods.vgetfield; tif->tif_tagmethods.vgetfield = PixarLogVGetField; /* hook for codec tags */ sp->vsetparent = tif->tif_tagmethods.vsetfield; @@ -1345,7 +1355,7 @@ TIFFInitPixarLog(TIFF* tif, int scheme) return (1); bad: - TIFFErrorExt(tif->tif_clientdata, "TIFFInitPixarLog", + TIFFErrorExt(tif->tif_clientdata, module, "No space for PixarLog state block"); return (0); } diff --git a/libtiff/tif_predict.c b/libtiff/tif_predict.c index a80e3dad..3124d82e 100644 --- a/libtiff/tif_predict.c +++ b/libtiff/tif_predict.c @@ -1,4 +1,4 @@ -/* $Id: tif_predict.c,v 1.15 2007-04-04 04:16:07 joris Exp $ */ +/* $Id: tif_predict.c,v 1.16 2007-04-07 15:14:31 dron Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -538,7 +538,6 @@ static const TIFFFieldInfo predictFieldInfo[] = { { TIFFTAG_PREDICTOR, 1, 1, TIFF_SHORT, FIELD_PREDICTOR, FALSE, FALSE, "Predictor" }, }; -#define N(a) (sizeof (a) / sizeof (a[0])) static int PredictorVSetField(TIFF* tif, uint32 tag, va_list ap) @@ -605,10 +604,18 @@ TIFFPredictorInit(TIFF* tif) assert(sp != 0); /* - * Merge codec-specific tag information and - * override parent get/set field methods. + * Merge codec-specific tag information. + */ + if (!_TIFFMergeFieldInfo(tif, predictFieldInfo, + TIFFArrayCount(predictFieldInfo))) { + TIFFErrorExt(tif->tif_clientdata, "TIFFPredictorInit", + "Merging Predictor codec-specific tags failed"); + return 0; + } + + /* + * Override parent get/set field methods. */ - _TIFFMergeFieldInfo(tif, predictFieldInfo, N(predictFieldInfo)); sp->vgetparent = tif->tif_tagmethods.vgetfield; tif->tif_tagmethods.vgetfield = PredictorVGetField;/* hook for predictor tag */ diff --git a/libtiff/tif_zip.c b/libtiff/tif_zip.c index 355c6622..361b849e 100644 --- a/libtiff/tif_zip.c +++ b/libtiff/tif_zip.c @@ -1,4 +1,4 @@ -/* $Id: tif_zip.c,v 1.13 2007-03-31 01:41:11 joris Exp $ */ +/* $Id: tif_zip.c,v 1.14 2007-04-07 15:14:31 dron Exp $ */ /* * Copyright (c) 1995-1997 Sam Leffler @@ -342,11 +342,22 @@ static const TIFFFieldInfo zipFieldInfo[] = { int TIFFInitZIP(TIFF* tif, int scheme) { + const char module[] = "TIFFInitZIP"; ZIPState* sp; assert( (scheme == COMPRESSION_DEFLATE) || (scheme == COMPRESSION_ADOBE_DEFLATE)); + /* + * Merge codec-specific tag information. + */ + if (!_TIFFMergeFieldInfo(tif, zipFieldInfo, + TIFFArrayCount(zipFieldInfo))) { + TIFFErrorExt(tif->tif_clientdata, module, + "Merging Deflate codec-specific tags failed"); + return 0; + } + /* * Allocate state block so tag methods have storage to record values. */ @@ -360,10 +371,8 @@ TIFFInitZIP(TIFF* tif, int scheme) sp->stream.data_type = Z_BINARY; /* - * Merge codec-specific tag information and - * override parent get/set field methods. + * Override parent get/set field methods. */ - _TIFFMergeFieldInfo(tif, zipFieldInfo, TIFFArrayCount(zipFieldInfo)); sp->vgetparent = tif->tif_tagmethods.vgetfield; tif->tif_tagmethods.vgetfield = ZIPVGetField; /* hook for codec tags */ sp->vsetparent = tif->tif_tagmethods.vsetfield; @@ -394,7 +403,7 @@ TIFFInitZIP(TIFF* tif, int scheme) (void) TIFFPredictorInit(tif); return (1); bad: - TIFFErrorExt(tif->tif_clientdata, "TIFFInitZIP", + TIFFErrorExt(tif->tif_clientdata, module, "No space for ZIP state block"); return (0); }