Return-Path: <awaresystems.be+caf_=filtered=awaresystems.be@gmail.com>
Delivered-To: filtered@awaresystems.be
Received: from mx-x.one.com (mx-x.one.com [195.47.247.149])
	by mail6.local (Postfix) with ESMTP id 99B6E300306298
	for <filtered@awaresystems.be>; Fri,  9 May 2014 13:22:24 +0000 (UTC)
X-Virus-Scanned: by one.com
Received-SPF: pass (mx-x: domain of awaresystems.be+caf_=filtered=awaresystems.be@gmail.com designates 209.85.215.49 as permitted sender)
X-Greylist: whitelisted by SQLgrey-1.8.0-rc2
Received: from mail-la0-f49.google.com (mail-la0-f49.google.com [209.85.215.49])
	by mx-x.one.com (Postfix) with ESMTP id 5E52C2069D1C5
	for <filtered@awaresystems.be>; Fri,  9 May 2014 13:22:24 +0000 (UTC)
Received: by mail-la0-f49.google.com with SMTP id pv20so195063lab.8
        for <filtered@awaresystems.be>; Fri, 09 May 2014 06:22:24 -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:references:mime-version:content-disposition
         :in-reply-to: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=K/6GBUPE7NKrBxHDlzGpE1K6mpep4nix4s5pbr552U4=;
        b=WkNaQjCoB0xNXG7AIg/6CsumMtaafWN4byLFuFpHaa3E3ecuaHCe6N0LXqzexv21fv
         1ZOudgVLJHkB8p6vFTT8iB080q9pONWZLAzXaMR4VbnSLJsaGEsZLWyV6lT9ZIiWe/Nf
         4OkfFXvPI8rLyDAaxWrWtQKWBD8DOc42Oa/i2yWNibxD5fhjEQ6VUngnt1jr93wwXqj/
         qpHR/tTn21PAioFn/VPBcl89Wqp4psiitMZZ6LjPmnvbZnqOeS4N29Q0cAx7wBKFtOgk
         h4wKtFiPbTCjStBzzcdy5RgoWfSdCQSZ3Y+vBeMrTJt8euqtkJikBKqJts6MY2Ire0MP
         wHbQ==
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.112.149.71 with SMTP id ty7mr2110657lbb.34.1399641744023;
        Fri, 09 May 2014 06:22:24 -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 q4csp126345ldb;
        Fri, 9 May 2014 06:22:23 -0700 (PDT)
X-Received: by 10.152.23.42 with SMTP id j10mr1940090laf.19.1399641741702;
        Fri, 09 May 2014 06:22:21 -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=195.47.247.149;
Received: by 10.152.105.106 with POP3 id gl10mf216081lab.4;
        Fri, 09 May 2014 06:22:21 -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-x.one.com (mx-x.one.com [195.47.247.149])
	by mail6.local (Postfix) with ESMTP id 427C8300306298
	for <info@awaresystems.be>; Fri,  9 May 2014 13:19:15 +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-x.one.com (Postfix) with ESMTP id 21E1F2036252A
	for <info@awaresystems.be>; Fri,  9 May 2014 13:19:14 +0000 (UTC)
Received: from [10.1.0.241] (localhost.localdomain [127.0.0.1])
	by lists.maptools.org (Postfix) with ESMTP id 869A235C050;
	Fri,  9 May 2014 08:18:14 -0500 (EST)
Received: from nagini.codelibre.net (nagini.codelibre.net [80.68.93.164])
	by lists.maptools.org (Postfix) with ESMTP id F0A4D35C04D
	for <tiff@lists.maptools.org>; Fri,  9 May 2014 08:18:05 -0500 (EST)
Received: by nagini.codelibre.net (Postfix, from userid 1000)
	id 957C518574; Fri,  9 May 2014 14:17:57 +0100 (BST)
Date: Fri, 9 May 2014 14:17:57 +0100
From: Roger Leigh <rleigh@codelibre.net>
To: tiff@lists.maptools.org
Message-ID: <20140509131757.GW30912@codelibre.net>
References: <20140509120600.GU30912@codelibre.net>
MIME-Version: 1.0
Content-Disposition: inline
In-Reply-To: <20140509120600.GU30912@codelibre.net>
User-Agent: Mutt/1.5.21 (2010-09-15)
Subject: Re: [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

On Fri, May 09, 2014 at 01:06:00PM +0100, Roger Leigh wrote:
> 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.

Simple testcase:


#include <stdio.h>
#include <tiffio.h>
#include <stdint.h>
#include <stdbool.h>

int main(void)
{
  TIFF *tiff = TIFFOpen("test.tiff", "r");

  TIFFSetDirectory(tiff, 1);
  for (int i = 0; i < 10; ++i)
  {
    uint64_t offset = TIFFCurrentDirOffset(tiff);
    uint16_t index = TIFFCurrentDirectory(tiff);
    bool last = TIFFLastDirectory(tiff);
    printf("index=%u, offset=%lu, last=%d\n", index, offset, last);
    TIFFSetSubDirectory(tiff, offset);
    TIFFSetSubDirectory(tiff, offset);
  }
}

==>
index=1, offset=839, last=0
index=3, offset=839, last=0
index=5, offset=839, last=0
index=7, offset=839, last=0
index=9, offset=839, last=0
index=11, offset=839, last=0
index=13, offset=839, last=0
index=15, offset=839, last=0
index=17, offset=839, last=0
index=19, offset=839, last=0

Every call to TIFFSetSubDirectory is incrementing the index returned by
TIFFCurrentDirectory.  Even though, in fact, the IFD never actually
changed since the IFD offset was constant from the moment TIFFOpen
returned.

Is this a libtiff bug, or is this working as intended?


Regards,
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/
