AWARE SYSTEMS
TIFF and LibTiff Mail List Archive

1998.12.10 20:57 "tiffcp bug & libtiff maint.", by Frank Warmerdam

Sam / and others,

I have found, and fixed a bug in tiffcp. In particular, if you attempt to convert the test image oxford.tif to tiled format (it has separate image planes) I get a crash.

% tiffcp -t oxford.tif oxford_tiled.tif

Investigation took me to the function readSeparateStripsIntoBuffer(). It is manifestly in error since nothing in the function actually references the scanline buffer into which the data is being read.

DECLAREreadFunc(readSeparateStripsIntoBuffer)
{
        tsize_t scanlinesize = TIFFScanlineSize(in);
        tdata_t scanline = _TIFFmalloc(scanlinesize);

        (void) imagewidth;
        if (scanline) {
                uint8* bufp = (uint8*) buf;
                uint32 row;
                tsample_t s;

                for (row = 0; row < imagelength; row++) {
                        /* merge channels */
                        for (s = 0; s < spp; s++) {
                                uint8* bp = bufp + s;
                                tsize_t n = scanlinesize;

                                if (TIFFReadScanline(in, scanline, row, s) < 0 && !ignore)
                                        goto done;
                                while (n-- > 0)
                                        *bp = *bufp++, bp += spp;
                        }
                        bufp += scanlinesize;
                }
done:
                _TIFFfree(scanline);
        }
}

I made a few changes to produce this version.

DECLAREreadFunc(readSeparateStripsIntoBuffer)
{
        tsize_t scanlinesize = TIFFScanlineSize(in);
        tdata_t scanline = _TIFFmalloc(scanlinesize);

        (void) imagewidth;
        if (scanline) {
                uint8* bufp = (uint8*) buf;
                uint32 row;
                tsample_t s;

                for (row = 0; row < imagelength; row++) {
                        /* merge channels */
                        for (s = 0; s < spp; s++) {
                                uint8* bp = bufp + s;
                                tsize_t n = scanlinesize;
                                uint8* sbuf = scanline;     /** new **/

                                if (TIFFReadScanline(in, scanline, row, s) < 0 && !ignore)
                                        goto done;
                                while (n-- > 0)
                                        *bp = *sbuf++, bp += spp;  /** changed **/
                        }
                        bufp += scanlinesize * spp;         /** changed **/
                }

done:
                _TIFFfree(scanline);
        }
}

After this change the resulting file works fine with some applications, though it confusing my local version of xv. I also tried converting this file back to strip organization, and got a screwed up file. Looking at the image, it seemed to be emitting the extra data in the last tile, or perhaps over compensating for it's presence.

Using:

% tiffcp -s oxford_tiled.tif oxford_stripped.tif

Would you like me to look into this problem as well?

These problems came up as I was trying to synthesis various test files to use with me new TIFFReadRGBAStrip(), and TIFFReadRGBATile() functions which otherwise seem to be working well. I will send them through in the next day or two.

--- on another topic ---

Finally, for the maintenance of the software, perhaps libtiff could move to a situation where it is kept under CVS and two or three trusted people could have access. I for one would like to see a new libtiff version produced with my new RGBA access functions fairly quickly as it would make it easier to ensure that my changes have been folded in properly, and that my clients won't have trouble upgrading to new versions of the library. The changes aren't very critical, and Sam might not have time to do a release of such stuff for a while.

If there were to fly, we would need somewhere we could host a tiff site (which I would also hope could be a new home for GeoTIFF stuff... my main area of interest). This could be SGI, but only if they aren't too picky about security, and only if Sam was willing to do a bunch of grunt work.

Alternatively, perhaps it could be hosted on the machine of some other established, and related project such as the IJG, Gimp, PNM or such. A key factor to my mind is that the host should be reliable, and care enough about tiff to not let it get unduely hosed.

I would be happy to do some grunt work on this sort of thing as long as appropriate access can be given.

Best regards,

-----------------------------------+---------------------------------------
Who can give them back their lives | Frank Warmerdam, Programmer for Hire
and all those wasted years? - Rush | http://members.home.com/warmerda
                                   | warmerda@home.com