Return-Path: <tiff-bounces@lists.maptools.org>
X-Original-To: info@awaresystems.be
Delivered-To: info@awaresystems.be
Received: from mx-c.b-one.net (mx-c.one.com [91.198.169.50])
	by mail9.b-one.net (Postfix) with ESMTP id 03CDE400164
	for <info@awaresystems.be>; Mon, 30 Nov 2009 12:33:00 +0100 (CET)
X-Virus-Scanned: by one.com
X-Spam-Score: 0
X-Spam-Level: 
X-Spam-Status: No, score=0 tagged_above=0 required=6 tests=[none]
X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4
Received: from lists.maptools.org (lists.maptools.org [65.39.174.144])
	by mx-c.b-one.net (Postfix) with ESMTP id 4FDA8590
	for <info@awaresystems.be>; Mon, 30 Nov 2009 12:32:59 +0100 (CET)
Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
	by lists.maptools.org (Postfix) with ESMTP id 457511D11B6C1;
	Mon, 30 Nov 2009 06:32:07 -0500 (EST)
Received: from mailout11.t-online.de (mailout11.t-online.de [194.25.134.85])
	by lists.maptools.org (Postfix) with ESMTP id 1AF141D18E513
	for <tiff@lists.maptools.org>; Mon, 30 Nov 2009 06:27:09 -0500 (EST)
Received: from fwd01.aul.t-online.de by mailout11.t-online.de with smtp 
	id 1NF4PM-0003Vm-01; Mon, 30 Nov 2009 12:27:08 +0100
Received: from ubuntu
	(JO+-j4ZAwhEmoBuDSObGAPGIs0SmuWhXaDmZsv-km7VKl3Z9GxBVVyYk942wP6QgTp@[91.55.65.190])
	by fwd01.t-online.de
	with esmtp id 1NF4P6-2JiWnI0; Mon, 30 Nov 2009 12:26:52 +0100
Date: Mon, 30 Nov 2009 12:26:51 +0100
From: Juergen Buchmueller <pullmoll@t-online.de>
To: tiff@lists.maptools.org
Message-Id: <20091130122651.b4bc427a.pullmoll@t-online.de>
X-Mailer: Sylpheed 2.7.1 (GTK+ 2.18.3; x86_64-pc-linux-gnu)
Mime-Version: 1.0
Content-Type: multipart/mixed;
	boundary="Multipart=_Mon__30_Nov_2009_12_26_51_+0100_a+KN6l+732xqyUgn"
X-ID: JO+-j4ZAwhEmoBuDSObGAPGIs0SmuWhXaDmZsv-km7VKl3Z9GxBVVyYk942wP6QgTp
X-TOI-MSGID: 7f82804e-0e33-4396-9a4e-3e9112262ad0
Subject: [Tiff] Adding tags to a broken(?) TIFF
X-BeenThere: tiff@lists.maptools.org
X-Mailman-Version: 2.1.9
Precedence: list
List-Id: TIFF and libtiff discussion <tiff.lists.maptools.org>
List-Unsubscribe: <http://lists.maptools.org/mailman/listinfo/tiff>,
	<mailto:tiff-request@lists.maptools.org?subject=unsubscribe>
List-Archive: <http://lists.maptools.org/mailman/private/tiff>
List-Post: <mailto:tiff@lists.maptools.org>
List-Help: <mailto:tiff-request@lists.maptools.org?subject=help>
List-Subscribe: <http://lists.maptools.org/mailman/listinfo/tiff>,
	<mailto:tiff-request@lists.maptools.org?subject=subscribe>
Sender: tiff-bounces@lists.maptools.org
Errors-To: tiff-bounces@lists.maptools.org

This is a multi-part message in MIME format.

--Multipart=_Mon__30_Nov_2009_12_26_51_+0100_a+KN6l+732xqyUgn
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit

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

--Multipart=_Mon__30_Nov_2009_12_26_51_+0100_a+KN6l+732xqyUgn
Content-Type: text/x-csrc;
 name="addtags.c"
Content-Disposition: attachment;
 filename="addtags.c"
Content-Transfer-Encoding: quoted-printable

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

static const char *some_strings[] =3D {
	"A098192515",
	"GBV",
	"UB L=FCneburg L=FCn4",
	"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 =3D TIFFOpen(argv[1], "r+");

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

	for (n =3D 0; n < ntags; n++) {
		str =3D some_strings[n];
		res =3D 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 =3D 0; n < ntags; n++) {
		if (apptags[n].field_name)
			free(apptags[n].field_name);
	}
	free(apptags);

	return 0;
}

--Multipart=_Mon__30_Nov_2009_12_26_51_+0100_a+KN6l+732xqyUgn
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Tiff mailing list: Tiff@lists.maptools.org
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
--Multipart=_Mon__30_Nov_2009_12_26_51_+0100_a+KN6l+732xqyUgn--
