AWARE [SYSTEMS] Imaging expertise for the Delphi developer
AWare Systems, Imaging expertise for the Delphi developer, Home TIFF and LibTiff Mailing List Archive

LibTiff Mailing List

TIFF and LibTiff Mailing List Archive
November 2009

Previous Thread
Next Thread

Previous by Thread
Next by Thread

Previous by Date
Next by Date

Contact

The TIFF Mailing List Homepage
This list is run by Frank Warmerdam
Archive maintained by AWare Systems



Valid HTML 4.01!



Thread

2009.11.30 11:26 "Adding tags to a broken(?) TIFF", by Juergen Buchmueller
2009.12.06 15:02 "Re: Adding tags to a broken(?) TIFF", by Juergen Buchmueller
2009.12.06 15:57 "Re: Adding tags to a broken(?) TIFF", by Bob Friesenhahn

2009.11.30 11:26 "Adding tags to a broken(?) TIFF", by Juergen Buchmueller

Hello *,

the linked TIFF (see below) seems to be broken in some kind and I'm not
able to tell how it is broken using the available TIFF tools. It looks
like the Fax data isn't kosher, i.e. there are invalid codes and/or
early EOLs.

What happens is that if I try to add some tags (see attached addtags.c)
to the first directory entry, the data of the first image is no longer
readable with libtiff. If, however, I first make a copy of broken.tiff
using tiffcp, I can add tags to the resulting tiff and still get the
image data. So tiffcp /cures/ the brokeness in some kind. The file size
increases by a few bytes (+74).

It seems that the brokeness of the original broken.tiff causes libtiff
to write the additional tags into some region of the file that has an
impact on the decoding of the (Fax) image data inside.

I'm not sure if this would be a bug in libtiff. It is definitely a bug
in the software of the creator of broken.tiff. Unfortunately I can't
change that and have to deal with what I get from them.

I'd be grateful for any help how to deal with this,

Juergen

PS: I used libtiff-3.9.1 here, but the problem exists in 3.8.2 also.

Download link: http://rapidshare.com/files/314235584/broken.tiff

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <tiffio.h>

static const char *some_strings[] = {
	"A098192515",
	"GBV",
	"UB Lüneburg Lün4",
	"193.174.47.138",
	"end"
};


int main(int argc, char **argv)
{
	TIFF *hTIFF;
	TIFFFieldInfo *apptags;
	char buff[32];
	const char *str;
	uint32_t n, ntags;
	int32_t res;

	hTIFF = TIFFOpen(argv[1], "r+");

	ntags = 4;
	apptags = calloc(ntags, sizeof(TIFFFieldInfo));
	for (n = 0; n < ntags; n++) {
		uint16_t id = 10000 + n;
		apptags[n].field_tag = id;
		apptags[n].field_readcount = TIFF_VARIABLE;
		apptags[n].field_writecount = TIFF_VARIABLE;
		apptags[n].field_type = TIFF_ASCII;
		apptags[n].field_bit = FIELD_CUSTOM;
		apptags[n].field_oktochange = 1;
		apptags[n].field_passcount = 0;
		snprintf(buff, sizeof(buff), "test%d", id);
		apptags[n].field_name = strdup(buff);
	}
	TIFFMergeFieldInfo(hTIFF, apptags, ntags);

	for (n = 0; n < ntags; n++) {
		str = some_strings[n];
		res = TIFFSetField(hTIFF, apptags[n].field_tag, str);
		printf("set tag:%u to \"%s\" res:%d\n",
			apptags[n].field_tag, str, res);
	}

	TIFFWriteDirectory(hTIFF);

	TIFFClose(hTIFF);

	for (n = 0; n < ntags; n++) {
		if (apptags[n].field_name)
			free(apptags[n].field_name);
	}
	free(apptags);

	return 0;
}