diff options
-rw-r--r-- | libtiff/tif_dirread.c | 4 | ||||
-rw-r--r-- | tools/tiffinfo.c | 66 |
2 files changed, 65 insertions, 5 deletions
diff --git a/libtiff/tif_dirread.c b/libtiff/tif_dirread.c index 3c5adb2b..4950b82c 100644 --- a/libtiff/tif_dirread.c +++ b/libtiff/tif_dirread.c @@ -864,7 +864,7 @@ static enum TIFFReadDirEntryErr TIFFReadDirEntryArrayWithLimit( datasize=(*count)*typesize; assert((tmsize_t)datasize>0); - if( isMapped(tif) && datasize > (uint32)tif->tif_size ) + if( isMapped(tif) && datasize > (uint64)tif->tif_size ) return TIFFReadDirEntryErrIo; if( !isMapped(tif) && @@ -3400,7 +3400,7 @@ TIFFReadDirEntryData(TIFF* tif, uint64 offset, tmsize_t size, void* dest) return TIFFReadDirEntryErrIo; } mb=ma+size; - if (mb > (size_t)tif->tif_size) + if (mb > (uint64)tif->tif_size) return(TIFFReadDirEntryErrIo); _TIFFmemcpy(dest,tif->tif_base+ma,size); } diff --git a/tools/tiffinfo.c b/tools/tiffinfo.c index 049e3a34..30b3d3ba 100644 --- a/tools/tiffinfo.c +++ b/tools/tiffinfo.c @@ -407,11 +407,11 @@ ShowRawWords(uint16* pp, uint32 n) putchar('\n'); } -void -TIFFReadRawData(TIFF* tif, int bitrev) +static void +TIFFReadRawDataStriped(TIFF* tif, int bitrev) { tstrip_t nstrips = TIFFNumberOfStrips(tif); - const char* what = TIFFIsTiled(tif) ? "Tile" : "Strip"; + const char* what = "Strip"; uint64* stripbc=NULL; TIFFGetField(tif, TIFFTAG_STRIPBYTECOUNTS, &stripbc); @@ -456,6 +456,66 @@ TIFFReadRawData(TIFF* tif, int bitrev) } static void +TIFFReadRawDataTiled(TIFF* tif, int bitrev) +{ + const char* what = "Tile"; + uint32 ntiles = TIFFNumberOfTiles(tif); + uint64 *tilebc; + + TIFFGetField(tif, TIFFTAG_TILEBYTECOUNTS, &tilebc); + if (tilebc != NULL && ntiles > 0) { + uint64 bufsize = 0; + tdata_t buf = NULL; + uint32 t; + + for (t = 0; t < ntiles; t++) { + if (buf == NULL || tilebc[t] > bufsize) { + buf = _TIFFrealloc(buf, (tmsize_t)tilebc[t]); + bufsize = tilebc[t]; + } + if (buf == NULL) { + fprintf(stderr, + "Cannot allocate buffer to read tile %lu\n", + (unsigned long) t); + break; + } + if (TIFFReadRawTile(tif, t, buf, (tmsize_t)tilebc[t]) < 0) { + fprintf(stderr, "Error reading tile %lu\n", + (unsigned long) t); + if (stoponerr) + break; + } else if (showdata) { + if (bitrev) { + TIFFReverseBits(buf, (tmsize_t)tilebc[t]); + printf("%s %lu: (bit reversed)\n ", + what, (unsigned long) t); + } else { + printf("%s %lu:\n ", what, + (unsigned long) t); + } + if (showwords) { + ShowRawWords((uint16*) buf, (uint32)(tilebc[t]>>1)); + } else { + ShowRawBytes((unsigned char*) buf, (uint32) tilebc[t]); + } + } + } + if (buf != NULL) + _TIFFfree(buf); + } +} + +void +TIFFReadRawData(TIFF* tif, int bitrev) +{ + if (TIFFIsTiled(tif)) { + TIFFReadRawDataTiled(tif, bitrev); + } else { + TIFFReadRawDataStriped(tif, bitrev); + } +} + +static void tiffinfo(TIFF* tif, uint16 order, long flags, int is_image) { TIFFPrintDirectory(tif, stdout, flags); |