2016.09.19 16:29 "[Tiff] Accuracy of TIFF Field metadata (COLORMAP)", by

2016.09.20 09:02 "Re: [Tiff] Accuracy of TIFF Field metadata (COLORMAP)", by

On 2016-09-19 18:47, mickey.rose@seznam.cz wrote:

I recently discovered a problem on Windows where I was getting a strange runtime error ("Run-Time Check Failure #2 -S") which turns out was due to stack corruption. This was due to calling TIFFGetField with the wrong parameters, and that was because the field metadata in tif_dirinfo.c was wrong. Here's the broken bit:

         { TIFFTAG_COLORMAP, -1, -1, TIFF_SHORT, 0, TIFF_SETGET_OTHER,

TIFF_SETGET_UNDEFINED, FIELD_COLORMAP, 1, 0, "ColorMap", NULL },

These values are correct. There's field_passcount=0, which means you shouldn't be asking for the nunber of colors (&n in your code) from TIFFGetField. See:

https://github.com/vadz/libtiff/blob/c87dc82d7ff8214bd417176bd76f3fe94a237659/libtiff/tif_dir.c#L327

TIFFGetField gives you the three uint16* pointers to r/g/b arrays, whose length, i.e. the number of colors in the palette, is determined by bitspersample (n = 1<<bitspersample)

I'm not sure I follow completely.

        unsigned char field_passcount;  /* if true, pass dir count on set */

This is a "get" operation I'm performing, so I'm not sure it applies. Does it also apply to get?

Additionally, where is it specified that the value is "1<<bitspersample"? I know it's in the specification e.g. http://www.awaresystems.be/imaging/tiff/tifftags/colormap.html. What I mean is I'm trying to write this code without any specific prior knowledge of the tag types, and I'd like to obtain that information from libtiff itself, without making any assumptions in my code. Is that possible to obtain in any way?

Is the read count here really valid being TIFF_VARIABLE? Why would TIFFFieldReadCount not return the actual size? i.e. 1<<bitspersample. Or would it be appropriate to add

#define TIFF_BPS       -4              /* marker for BitsPerSample 

length tags */

and use that instead?

Basically I'm looking for a way to correctly introspect this information, since I can't see how I could get this with the existing API, unless I'm not seeing something basic. Is anything which is TIFF_VARIABLE or TIFF_VARIABLE2 with passcount==0 automatically assumed to be 1<<bitspersample in length? If so, is that universally true, or are there any exceptions to the rule?

Assuming I'm not totally wrong in my understanding, the wider question here is this: is the field metadata generally usable? Or does it need a proper audit of every field to ensure the types are correct in every case? Would it help to use the VARIABLE/VARIABLE2/SPP values in place of negative values?

There's a comment at the top acknowledging that symbolic names should be used, and something about formatting... I assume they'd make the table a bit harder to skim through.

Maybe if each field was split over two lines it would fit better?

Regards,

Roger