Commit 9752dae8 authored by Even Rouault's avatar Even Rouault
Browse files

Merge branch 'fix_#8_FreeAnonTag' into 'master'

extra flag for anonymous (unknown) tags (fixes #8)

Closes #400 et #8

See merge request !324
parents b4e79bfa 97574866
Pipeline #523047030 passed with stages
in 10 minutes and 57 seconds
......@@ -29,6 +29,7 @@ EXPORTS TIFFAccessTagMethods
TIFFFieldName
TIFFFieldPassCount
TIFFFieldReadCount
TIFFFieldIsAnonymous
TIFFFieldTag
TIFFFieldWithName
TIFFFieldWithTag
......@@ -177,3 +178,4 @@ EXPORTS TIFFAccessTagMethods
_TIFFMultiply64
_TIFFGetExifFields
_TIFFGetGpsFields
......@@ -82,7 +82,10 @@ TIFFCleanup(TIFF* tif)
TIFFField *fld = tif->tif_fields[i];
if (fld->field_name != NULL) {
if (fld->field_bit == FIELD_CUSTOM &&
strncmp("Tag ", fld->field_name, 4) == 0) {
/* catuion: tif_fields[i] must not be the beginning of a fields-array.
* Otherwise the following tags are also freed with the first free().
*/
TIFFFieldIsAnonymous(fld)) {
_TIFFfree(fld->field_name);
_TIFFfree(fld);
}
......
......@@ -282,11 +282,11 @@ struct _TIFFFieldArray {
};
struct _TIFFField {
uint32_t field_tag; /* field's tag */
uint32_t field_tag; /* field's tag */
short field_readcount; /* read count/TIFF_VARIABLE/TIFF_SPP */
short field_writecount; /* write count/TIFF_VARIABLE */
TIFFDataType field_type; /* type of associated data */
uint32_t reserved; /* reserved for future extension */
uint32_t field_anonymous; /* if true, this is a unknown / anonymous tag */
TIFFSetGetFieldType set_field_type; /* type to be passed to TIFFSetField */
TIFFSetGetFieldType get_field_type; /* type to be passed to TIFFGetField */
unsigned short field_bit; /* bit in fieldsset bit vector */
......
......@@ -422,8 +422,11 @@ _TIFFSetupFields(TIFF* tif, const TIFFFieldArray* fieldarray)
TIFFField *fld = tif->tif_fields[i];
if (fld->field_name != NULL) {
if (fld->field_bit == FIELD_CUSTOM &&
strncmp("Tag ", fld->field_name, 4) == 0) {
TIFFFieldIsAnonymous(fld)) {
_TIFFfree(fld->field_name);
/* catuion: tif_fields[i] must not be the beginning of a fields-array.
* Otherwise the following tags are also freed with the first free().
*/
_TIFFfree(fld);
}
}
......@@ -791,6 +794,12 @@ TIFFFieldWriteCount(const TIFFField* fip)
return fip->field_writecount;
}
int
TIFFFieldIsAnonymous(const TIFFField *fip)
{
return fip->field_anonymous;
}
const TIFFField*
_TIFFFindOrRegisterField(TIFF *tif, uint32_t tag, TIFFDataType dt)
......@@ -822,7 +831,7 @@ _TIFFCreateAnonField(TIFF *tif, uint32_t tag, TIFFDataType field_type)
fld->field_readcount = TIFF_VARIABLE2;
fld->field_writecount = TIFF_VARIABLE2;
fld->field_type = field_type;
fld->reserved = 0;
fld->field_anonymous = 1; /* indicate that this is an anonymous / unknown tag */
switch (field_type)
{
case TIFF_BYTE:
......@@ -895,6 +904,8 @@ _TIFFCreateAnonField(TIFF *tif, uint32_t tag, TIFFDataType field_type)
/*
* note that this name is a special sign to TIFFClose() and
* _TIFFSetupFields() to free the field
* Update:
* This special sign is replaced by fld->field_anonymous flag.
*/
(void) snprintf(fld->field_name, 32, "Tag %d", (int) tag);
......@@ -1105,7 +1116,7 @@ TIFFMergeFieldInfo(TIFF* tif, const TIFFFieldInfo info[], uint32_t n)
tp->field_readcount = info[i].field_readcount;
tp->field_writecount = info[i].field_writecount;
tp->field_type = info[i].field_type;
tp->reserved = 0;
tp->field_anonymous = 0;
tp->set_field_type =
_TIFFSetGetType(info[i].field_type,
info[i].field_readcount,
......
......@@ -4537,7 +4537,7 @@ TIFFReadCustomDirectory(TIFF* tif, toff_t diroff,
switch (dp->tdir_tag)
{
case EXIFTAG_SUBJECTDISTANCE:
if(fip->field_name != NULL && strncmp(fip->field_name, "Tag ", 4) != 0 ) {
if(!TIFFFieldIsAnonymous(fip)) {
/* should only be called on a Exif directory */
/* when exifFields[] is active */
(void)TIFFFetchSubjectDistance(tif, dp);
......
......@@ -81,7 +81,7 @@ _TIFFPrintField(FILE* fd, const TIFFField *fip,
/* Print a user-friendly name for tags of relatively common use, but */
/* which aren't registered by libtiff itself. */
const char* field_name = fip->field_name;
if( fip->field_name != NULL && strncmp(fip->field_name, "Tag ", 4) == 0 ) {
if( TIFFFieldIsAnonymous(fip) ) {
for( size_t i = 0; i < NTAGS; ++i ) {
if( fip->field_tag == tagnames[i].tag ) {
field_name = tagnames[i].name;
......@@ -149,7 +149,7 @@ _TIFFPrettyPrintField(TIFF* tif, const TIFFField *fip, FILE* fd, uint32_t tag,
(void) tif;
/* do not try to pretty print auto-defined fields */
if (fip->field_name != NULL && strncmp(fip->field_name,"Tag ", 4) == 0) {
if ( TIFFFieldIsAnonymous(fip) ) {
return 0;
}
......
......@@ -328,6 +328,7 @@ extern TIFFDataType TIFFFieldDataType(const TIFFField*);
extern int TIFFFieldPassCount(const TIFFField*);
extern int TIFFFieldReadCount(const TIFFField*);
extern int TIFFFieldWriteCount(const TIFFField*);
extern int TIFFFieldIsAnonymous(const TIFFField *);
typedef int (*TIFFVSetMethod)(TIFF*, uint32_t, va_list);
typedef int (*TIFFVGetMethod)(TIFF*, uint32_t, va_list);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment