diff options
author | Even Rouault <even.rouault@spatialys.com> | 2021-11-26 15:02:36 +0000 |
---|---|---|
committer | Even Rouault <even.rouault@spatialys.com> | 2021-11-26 15:02:36 +0000 |
commit | 31e3e939747bc794e3fe615682e90a3b2bc89443 (patch) | |
tree | 395b0eb2770e4b403fc495cde33a96dda7a2d94e | |
parent | 29219a5bd14040d60e376324a52ef91b68808143 (diff) | |
parent | 7db4f2b62206b9cba6cda538e0f296df0ac371bd (diff) | |
download | libtiff-git-31e3e939747bc794e3fe615682e90a3b2bc89443.tar.gz |
Merge branch 'GPS_Print_BugFix' into 'master'
Fix Segmentation fault printing GPS directory if Altitude tag is present (tif_print.c/tiffinfo.c)
See merge request libtiff/libtiff!272
-rw-r--r-- | libtiff/tif_dirinfo.c | 6 | ||||
-rw-r--r-- | libtiff/tif_print.c | 20 | ||||
-rw-r--r-- | test/CMakeLists.txt | 2 | ||||
-rw-r--r-- | test/Makefile.am | 3 | ||||
-rw-r--r-- | test/images/custom_dir_EXIF_GPS.tiff | bin | 0 -> 2504 bytes | |||
-rw-r--r-- | tools/tiffinfo.c | 14 |
6 files changed, 33 insertions, 12 deletions
diff --git a/libtiff/tif_dirinfo.c b/libtiff/tif_dirinfo.c index 3dbb830b..c6fc58f1 100644 --- a/libtiff/tif_dirinfo.c +++ b/libtiff/tif_dirinfo.c @@ -531,7 +531,7 @@ _TIFFPrintFieldInfo(TIFF* tif, FILE* fd) } /* - * Return size of TIFFDataType in bytes + * Return size of TIFFDataType within TIFF-file in bytes */ int TIFFDataWidth(TIFFDataType type) @@ -603,7 +603,7 @@ _TIFFDataSize(TIFFDataType type) /* * Rational2Double: - * Return size of TIFFSetGetFieldType in bytes. + * Return size of TIFFSetGetFieldType for internal storage in bytes. * * XXX: TIFF_RATIONAL values for FIELD_CUSTOM are stored internally as 4-byte float. * However, some of them should be stored internally as 8-byte double. @@ -620,7 +620,7 @@ _TIFFSetGetFieldSize(TIFFSetGetFieldType setgettype) case TIFF_SETGET_C16_ASCII: case TIFF_SETGET_C32_ASCII: case TIFF_SETGET_OTHER: - return 0; + return 1; case TIFF_SETGET_UINT8: case TIFF_SETGET_SINT8: case TIFF_SETGET_C0_UINT8: diff --git a/libtiff/tif_print.c b/libtiff/tif_print.c index 6e9f58ff..5a0305ed 100644 --- a/libtiff/tif_print.c +++ b/libtiff/tif_print.c @@ -108,10 +108,16 @@ _TIFFPrintField(FILE* fd, const TIFFField *fip, fprintf(fd, "%"PRId32, ((int32_t *) raw_data)[j]); else if(fip->field_type == TIFF_IFD) fprintf(fd, "0x%"PRIx32, ((uint32_t *) raw_data)[j]); - else if(fip->field_type == TIFF_RATIONAL - || fip->field_type == TIFF_SRATIONAL - || fip->field_type == TIFF_FLOAT) - fprintf(fd, "%f", ((float *) raw_data)[j]); + else if (fip->field_type == TIFF_RATIONAL + || fip->field_type == TIFF_SRATIONAL) { + int tv_size = _TIFFSetGetFieldSize(fip->set_field_type); + if(tv_size==8) + fprintf(fd, "%lf", ((double*)raw_data)[j]); + else + fprintf(fd, "%f", ((float *) raw_data)[j]); + } + else if(fip->field_type == TIFF_FLOAT) + fprintf(fd, "%f", ((float*)raw_data)[j]); else if(fip->field_type == TIFF_LONG8) fprintf(fd, "%"PRIu64, ((uint64_t *) raw_data)[j]); else if(fip->field_type == TIFF_SLONG8) @@ -238,7 +244,7 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags) char *sep; long l, n; - fprintf(fd, "TIFF Directory at offset 0x%"PRIu64" (%"PRIx64")\n", + fprintf(fd, "TIFF Directory at offset 0x%"PRIx64" (%"PRIu64")\n", tif->tif_diroff, tif->tif_diroff); if (TIFFFieldSet(tif,FIELD_SUBFILETYPE)) { @@ -614,8 +620,10 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags) if(TIFFGetField(tif, tag, &raw_data) != 1) continue; } else { + /*--: Rational2Double: For Rationals evaluate "set_field_type" to determine internal storage size. */ + int tv_size = _TIFFSetGetFieldSize(fip->set_field_type); raw_data = _TIFFmalloc( - _TIFFDataSize(fip->field_type) + tv_size * value_count); mem_alloc = 1; if(TIFFGetField(tif, tag, raw_data) != 1) { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 01b25a8d..53f8db73 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -111,6 +111,7 @@ set(TESTSCRIPTS # subdirectory which are intended to be used as input images for # tests. All of these files should use the extension ".tiff". set(TIFFIMAGES + images/custom_dir_EXIF_GPS.tiff images/logluv-3c-16b.tiff images/minisblack-1c-16b.tiff images/minisblack-1c-8b.tiff @@ -411,6 +412,7 @@ add_convert_test_multi(tiffcp thumbnail "" thumbnail "g3:1d" "" "" add_reader_test(tiffdump "" "images/miniswhite-1c-1b.tiff") # tiffinfo +add_reader_test(tiffinfo "-c -D -d -j -s" "images/custom_dir_EXIF_GPS.tiff") add_reader_test(tiffinfo "-c -D -d -j -s" "images/minisblack-1c-16b.tiff") # tiffcp split/join diff --git a/test/Makefile.am b/test/Makefile.am index 27d293e2..cb338884 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -184,7 +184,8 @@ TIFFIMAGES = \ images/ojpeg_chewey_subsamp21_multi_strip.tiff \ images/ojpeg_single_strip_no_rowsperstrip.tiff \ images/testfax4.tiff \ - images/deflate-last-strip-extra-data.tiff + images/deflate-last-strip-extra-data.tiff \ + images/custom_dir_EXIF_GPS.tiff PNMIMAGES = \ images/minisblack-1c-8b.pgm \ diff --git a/test/images/custom_dir_EXIF_GPS.tiff b/test/images/custom_dir_EXIF_GPS.tiff Binary files differnew file mode 100644 index 00000000..e34e6dc4 --- /dev/null +++ b/test/images/custom_dir_EXIF_GPS.tiff diff --git a/tools/tiffinfo.c b/tools/tiffinfo.c index 6921a0c5..12cd108c 100644 --- a/tools/tiffinfo.c +++ b/tools/tiffinfo.c @@ -155,12 +155,22 @@ main(int argc, char* argv[]) } else { do { toff_t offset=0; - + uint16_t curdir = TIFFCurrentDirectory(tif); + printf("=== TIFF directory %d ===\n", curdir); tiffinfo(tif, order, flags, 1); if (TIFFGetField(tif, TIFFTAG_EXIFIFD, - &offset)) { + &offset)) { if (TIFFReadEXIFDirectory(tif, offset)) { tiffinfo(tif, order, flags, 0); + /*-- Go back to previous directory, (directory is reloaded from file!) */ + TIFFSetDirectory(tif, curdir); + } + } + if (TIFFGetField(tif, TIFFTAG_GPSIFD, + &offset)) { + if (TIFFReadGPSDirectory(tif, offset)) { + tiffinfo(tif, order, flags, 0); + TIFFSetDirectory(tif, curdir); } } } while (TIFFReadDirectory(tif)); |