AWARE SYSTEMS
TIFF and LibTiff Mail List Archive

1999.08.16 16:40 "BYTE tag bug", by

Hi,

libtiff V3.4Beta 032, NT system (although I don't believe the bug is system dependent).

Summary:

Adding extra private tags of type BYTE (or BYTE array) doesn't work properly. I think I have identified the problem and I have included a possible fix.

Background:

I added some new tags to the library, using the xtiff_dir method contributed by Niles Ritter.

The tags I added included LONG, ASCII, BYTE and variable-array-of-BYTE type tags. I the method worked well for the LONG and ASCII type tags, but BYTE and BYTE array tags didn't write properly.

Solution:

I have tracked the problem down to TIFFWriteNormalTag in dir_write.c

The basic problem is that the switch statement in there doesn't handle the BYTE type case - it falls straight through.

My initial thought was that the UNDEFINED case might do pretty much what I wanted, but that isn't quite right either. I think adding the following case fixes the problem:

 case TIFF_BYTE:
  if (wc > 1) {
   char* cp;
   if (wc == (u_short) TIFF_VARIABLE) {
    TIFFGetField(tif, fip->field_tag, &wc, &cp);
    dir->tdir_count = wc;
   } else
    TIFFGetField(tif, fip->field_tag, &cp);
   if (!TIFFWriteByteArray(tif, dir, cp))
    return (0);
  } else {
   char cv;
   TIFFGetField(tif, fip->field_tag, &cv);
   if (!TIFFWriteByteArray(tif, dir, &cv))
    return (0);
  }

I think that the UNDEFINED case might also be incorrect, and perhaps needs to use the same code as above, but I am not sure.

Regards

Martin McBride