2005.03.03 17:19 "[Tiff] LibTIFF question", by Kalman Miklos

2005.03.15 00:38 "Re: [Tiff] LibTIFF question", by Joris Van Damme


I think you should be doing something like:

  uint16 count;
  int *data = NULL;

  TIFFGetField( m_TIFF, 50653, &count, &data );

That is almost a perfect solution, thanks to the so-called auto-registration. However, one thing seems missing, being the datatype. Suppose this method is used to retrieve, for example, the ModelPixelScaleTag tag value. If the calling code simply assumes the datatype of the returned value is DOUBLE, and only double-checks the count, it's bound to overrun the buffer pointed to by 'data' and crash badly if it ever encounters a TIFF file where this same tag id stores 3 byte values.

Due to the number of private tags, and due to the fact that at one time registration was hard, I expect some tag uses are unregistered and situations like these are likely. Besides, we need to protect ourselves from this mishap even if it should not be likely.

So my question is, is there a way to retrieve the datatype of these auto-registered tags? Am I right in thinking that TIFFFindFieldInfo with TIFF_ANY for the third parameter returns the 'registration' structure as build by this auto-registration scheme? Is checking the FieldType member of this structure good and sufficient to protect the calling code from the above mentioned mishap?

Joris Van Damme
Download your free TIFF tag viewer for windows here: