Return-Path: <awaresystems.be+caf_=filtered=awaresystems.be@gmail.com>
Delivered-To: filtered@awaresystems.be
Received: from mx-g.one.com (mx-g.one.com [91.198.169.54])
	by mail6.local (Postfix) with ESMTP id D69993001855D5
	for <filtered@awaresystems.be>; Fri,  9 May 2014 12:08:59 +0000 (UTC)
X-Virus-Scanned: by one.com
Received-SPF: pass (mx-g: domain of awaresystems.be+caf_=filtered=awaresystems.be@gmail.com designates 209.85.215.51 as permitted sender)
X-Greylist: whitelisted by SQLgrey-1.8.0-rc2
Received: from mail-la0-f51.google.com (mail-la0-f51.google.com [209.85.215.51])
	by mx-g.one.com (Postfix) with ESMTP id A08DB6F9FE2
	for <filtered@awaresystems.be>; Fri,  9 May 2014 12:08:59 +0000 (UTC)
Received: by mail-la0-f51.google.com with SMTP id gf5so371017lab.38
        for <filtered@awaresystems.be>; Fri, 09 May 2014 05:08:59 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-original-authentication-results:delivered-to:delivered-to:date
         :from:to:message-id:mime-version:content-disposition:user-agent
         :subject:precedence:list-id:list-unsubscribe:list-archive:list-post
         :list-help:list-subscribe:content-type:content-transfer-encoding
         :sender:errors-to;
        bh=ES+N6Vjz4MLtFjH2nhfeFCaOIwhAVCx/+lwXzU6ObkM=;
        b=euSlcJl2z+eLWMRcoAgJq9muV1TsvGBgbnYXA+yIhCdOL2sYdb4RA+i+yaaM+MZgxG
         IZzy8c944O/kTXYmlYT2mAfFC7jPgSOQXp5arRFCFts/2EyN0om46ciDEyOuJ9rix5Ul
         Ty3/ZCyFkEsIT7U1+hJRvVzt7vbSqall4/FKSo3GWAUvDMpntMLs5cPKrQbAJ17NAfCO
         65oipTfjZnwPgVWlpTzuShY+Rrrrfn9OH7bxrr7XRt4vlyJPjkLamdtjEqzdFUPZonrW
         l2+6t4NI6Y5dBWHtqq+s0ueKzZUyWuWfI5NB5mWGggtsADi0c8OPr7UkSeJkqSZ2+HFw
         8EXA==
X-Original-Authentication-Results: mx.google.com;       spf=neutral (google.com: tiff-bounces@lists.maptools.org does not designate permitted sender hosts) smtp.mail=tiff-bounces@lists.maptools.org
X-Received: by 10.152.6.194 with SMTP id d2mr1136065laa.54.1399637339229;
        Fri, 09 May 2014 05:08:59 -0700 (PDT)
X-Forwarded-To: filtered@awaresystems.be
X-Forwarded-For: awaresystems.be@gmail.com filtered@awaresystems.be
Delivered-To: awaresystems.be@gmail.com
Received: by 10.114.11.132 with SMTP id q4csp121561ldb;
        Fri, 9 May 2014 05:08:58 -0700 (PDT)
X-Received: by 10.152.23.6 with SMTP id i6mr1670764laf.24.1399637338644;
        Fri, 09 May 2014 05:08:58 -0700 (PDT)
Authentication-Results: mx.google.com;
       spf=neutral (google.com: tiff-bounces@lists.maptools.org does not designate permitted sender hosts) smtp.mail=tiff-bounces@lists.maptools.org
Received-SPF: none (google.com: tiff-bounces@lists.maptools.org does not designate permitted sender hosts) client-ip=91.198.169.49;
Received: by 10.152.135.244 with POP3 id pv20mf68588lab.7;
        Fri, 09 May 2014 05:08:58 -0700 (PDT)
X-Gmail-Fetch-Info: info@awaresystems.be 1 pop.awaresystems.be 110 info@awaresystems.be
Delivered-To: info@awaresystems.be
Received: from mx-b.one.com (mx-b.one.com [91.198.169.49])
	by mail6.local (Postfix) with ESMTP id AFE6F300306298
	for <info@awaresystems.be>; Fri,  9 May 2014 12:07:18 +0000 (UTC)
X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0-rc2
Received: from lists.maptools.org (ks365428.kimsufi.com [94.23.4.142])
	by mx-b.one.com (Postfix) with ESMTP id 6AE7CFE9F3F
	for <info@awaresystems.be>; Fri,  9 May 2014 12:07:18 +0000 (UTC)
Received: from [10.1.0.241] (localhost.localdomain [127.0.0.1])
	by lists.maptools.org (Postfix) with ESMTP id A29A535C03F;
	Fri,  9 May 2014 07:06:36 -0500 (EST)
Received: from nagini.codelibre.net (nagini.codelibre.net [80.68.93.164])
	by lists.maptools.org (Postfix) with ESMTP id 081F435C03F
	for <tiff@lists.maptools.org>; Fri,  9 May 2014 07:06:09 -0500 (EST)
Received: by nagini.codelibre.net (Postfix, from userid 1000)
	id F00B218574; Fri,  9 May 2014 13:06:00 +0100 (BST)
Date: Fri, 9 May 2014 13:06:00 +0100
From: Roger Leigh <rleigh@codelibre.net>
To: tiff@lists.maptools.org
Message-ID: <20140509120600.GU30912@codelibre.net>
MIME-Version: 1.0
Content-Disposition: inline
User-Agent: Mutt/1.5.21 (2010-09-15)
Subject: [Tiff] TIFFCurrentDirectory inconsistency
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>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Sender: tiff-bounces@lists.maptools.org
Errors-To: tiff-bounces@lists.maptools.org

Hi.  I'm using tiff 4.0.3 on Debian.

If I iterate over all IFDs in a TIFF by index using TIFFSetDirectory,
and for each IFD query the index, offset and whether it's last with
TIFFCurrentDirectory, TIFFCurrentDirOffset and TIFFLastDirectory I get
this:

[ RUN      ] TIFFTest.IFDsByIndex
IDX: 0   OFF: 8 LAST: 0
IDX: 1   OFF: 839 LAST: 0
IDX: 2   OFF: 1670 LAST: 0
IDX: 3   OFF: 2501 LAST: 0
IDX: 4   OFF: 3332 LAST: 0
IDX: 5   OFF: 4163 LAST: 0
IDX: 6   OFF: 4994 LAST: 0
IDX: 7   OFF: 5825 LAST: 0
IDX: 8   OFF: 6656 LAST: 0
IDX: 9   OFF: 7487 LAST: 1

All looks fine.  But, if I iterate by offset using TIFFSetSubDirectory:

[RUN      ] TIFFTest.IFDsByOffset
IDX: 5   OFF: 8 LAST: 0
IDX: 6   OFF: 839 LAST: 0
IDX: 7   OFF: 1670 LAST: 0
IDX: 8   OFF: 2501 LAST: 0
IDX: 9   OFF: 3332 LAST: 0
IDX: 10   OFF: 4163 LAST: 0
IDX: 11   OFF: 4994 LAST: 0
IDX: 12   OFF: 5825 LAST: 0
IDX: 13   OFF: 6656 LAST: 0
IDX: 14   OFF: 7487 LAST: 1

You can see here that while the offsets are identical, the indexes
returned by TIFFCurrentDirectory are now somewhat fictional.

Likewise, if I set the directory to index 0 with TIFFSetDirectory,
and then iterate using TIFFReadDirectory.  I'm calling
TIFFReadDirectory, then TIFFCurrentDirOffset,
then TIFFSetSubDirectory in a loop (I'm caching the offsets)

[ RUN      ] TIFFTest.IFDSimpleIter
IDX: 0   OFF: 8 LAST: 0
IDX: 4   OFF: 839 LAST: 0
IDX: 9   OFF: 1670 LAST: 0
IDX: 14   OFF: 2501 LAST: 0
IDX: 19   OFF: 3332 LAST: 0
IDX: 24   OFF: 4163 LAST: 0
IDX: 29   OFF: 4994 LAST: 0
IDX: 34   OFF: 5825 LAST: 0
IDX: 39   OFF: 6656 LAST: 0
IDX: 44   OFF: 7487 LAST: 1

Again, the offsets are incorrect.  And unlike the previous example,
they aren't just off by +5, it's incrementing by 4, then 5 for all
subsequent TIFFReadDirectory calls.

For the last example, if I call TIFFSetSubdirectory three times
in a row instead of once, the indexes change:

[ RUN      ] TIFFTest.IFDSimpleIter
IDX: 0   OFF: 8 LAST: 0
IDX: 10   OFF: 839 LAST: 0
IDX: 23   OFF: 1670 LAST: 0
IDX: 36   OFF: 2501 LAST: 0
IDX: 49   OFF: 3332 LAST: 0
IDX: 62   OFF: 4163 LAST: 0
IDX: 75   OFF: 4994 LAST: 0
IDX: 88   OFF: 5825 LAST: 0
IDX: 101   OFF: 6656 LAST: 0
IDX: 114   OFF: 7487 LAST: 1

My question is really just if this is expected behaviour or not?
Are the indexes expected to be valid if I've not called
TIFFSetDirectory explicitly, and instead used TIFFSetSubDirectory
or TIFFReadDirectory?  Something seems a bit amiss in how the index
is computed.


Many thanks,
Roger

-- 
  .''`.  Roger Leigh
 : :' :  Debian GNU/Linux    http://people.debian.org/~rleigh/
 `. `'   schroot and sbuild  http://alioth.debian.org/projects/buildd-tools
   `-    GPG Public Key      F33D 281D 470A B443 6756 147C 07B3 C8BC 4083 E800
_______________________________________________
Tiff mailing list: Tiff@lists.maptools.org
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
