2014.05.09 12:06 "[Tiff] TIFFCurrentDirectory inconsistency", by Roger Leigh

2014.05.09 13:17 "Re: [Tiff] TIFFCurrentDirectory inconsistency", by Roger Leigh

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