diff options
author | Even Rouault <even.rouault@spatialys.com> | 2020-01-12 14:53:59 +0100 |
---|---|---|
committer | Even Rouault <even.rouault@spatialys.com> | 2020-01-12 14:54:02 +0100 |
commit | 3db0ff91bc6db20fc4cb035be366a9bbb4e701cf (patch) | |
tree | 8648278c770735fb3333299e60ac43287b12cf50 /libtiff/tif_dirread.c | |
parent | 8192df23fa04f5e380c602790f16f4b0bb9371f3 (diff) | |
download | libtiff-git-3db0ff91bc6db20fc4cb035be366a9bbb4e701cf.tar.gz |
_TIFFPartialReadStripArray: bring back support for non-conformant SLONG8 data type
Such as in https://github.com/OSGeo/gdal/issues/2165
Diffstat (limited to 'libtiff/tif_dirread.c')
-rw-r--r-- | libtiff/tif_dirread.c | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/libtiff/tif_dirread.c b/libtiff/tif_dirread.c index 6f909413..be6fe24d 100644 --- a/libtiff/tif_dirread.c +++ b/libtiff/tif_dirread.c @@ -3902,11 +3902,37 @@ TIFFReadDirectory(TIFF* tif) break; case TIFFTAG_STRIPOFFSETS: case TIFFTAG_TILEOFFSETS: + switch( dp->tdir_type ) + { + case TIFF_SHORT: + case TIFF_LONG: + case TIFF_LONG8: + break; + default: + fip = TIFFFieldWithTag(tif,dp->tdir_tag); + TIFFWarningExt(tif->tif_clientdata,module, + "Invalid data type for tag %s", + fip ? fip->field_name : "unknown tagname"); + break; + } _TIFFmemcpy( &(tif->tif_dir.td_stripoffset_entry), dp, sizeof(TIFFDirEntry) ); break; case TIFFTAG_STRIPBYTECOUNTS: case TIFFTAG_TILEBYTECOUNTS: + switch( dp->tdir_type ) + { + case TIFF_SHORT: + case TIFF_LONG: + case TIFF_LONG8: + break; + default: + fip = TIFFFieldWithTag(tif,dp->tdir_tag); + TIFFWarningExt(tif->tif_clientdata,module, + "Invalid data type for tag %s", + fip ? fip->field_name : "unknown tagname"); + break; + } _TIFFmemcpy( &(tif->tif_dir.td_stripbytecount_entry), dp, sizeof(TIFFDirEntry) ); break; @@ -6034,6 +6060,12 @@ int _TIFFPartialReadStripArray( TIFF* tif, TIFFDirEntry* dirent, { sizeofval = sizeof(uint64); } + else if( dirent->tdir_type == TIFF_SLONG8 ) + { + /* Non conformant but used by some images as in */ + /* https://github.com/OSGeo/gdal/issues/2165 */ + sizeofval = sizeof(int64); + } else { TIFFErrorExt(tif->tif_clientdata, module, @@ -6106,7 +6138,7 @@ int _TIFFPartialReadStripArray( TIFF* tif, TIFFDirEntry* dirent, _TIFFUnsanitizedAddUInt64AndInt(nOffset, (i + 1) * sizeofvalint) <= nOffsetEndPage; ++i ) { - if( sizeofval == sizeof(uint16) ) + if( dirent->tdir_type == TIFF_SHORT ) { uint16 val; memcpy(&val, @@ -6116,7 +6148,7 @@ int _TIFFPartialReadStripArray( TIFF* tif, TIFFDirEntry* dirent, TIFFSwabShort(&val); panVals[strile + i] = val; } - else if( sizeofval == sizeof(uint32) ) + else if( dirent->tdir_type == TIFF_LONG ) { uint32 val; memcpy(&val, @@ -6126,7 +6158,7 @@ int _TIFFPartialReadStripArray( TIFF* tif, TIFFDirEntry* dirent, TIFFSwabLong(&val); panVals[strile + i] = val; } - else + else if( dirent->tdir_type == TIFF_LONG8 ) { uint64 val; memcpy(&val, @@ -6136,6 +6168,17 @@ int _TIFFPartialReadStripArray( TIFF* tif, TIFFDirEntry* dirent, TIFFSwabLong8(&val); panVals[strile + i] = val; } + else /* if( dirent->tdir_type == TIFF_SLONG8 ) */ + { + /* Non conformant data type */ + int64 val; + memcpy(&val, + buffer + (nOffset - nOffsetStartPage) + i * sizeofvalint, + sizeof(val)); + if( bSwab ) + TIFFSwabLong8((uint64*) &val); + panVals[strile + i] = (uint64) val; + } } return 1; } |