| diff --git a/third_party/libtiff/tif_dirread.c b/third_party/libtiff/tif_dirread.c |
| index 58c918181..e93072456 100644 |
| --- a/third_party/libtiff/tif_dirread.c |
| +++ b/third_party/libtiff/tif_dirread.c |
| @@ -3796,57 +3796,7 @@ TIFFReadDirectory(TIFF* tif) |
| MissingRequired(tif,"ImageLength"); |
| goto bad; |
| } |
| - /* |
| - * Setup appropriate structures (by strip or by tile) |
| - */ |
| - if (!TIFFFieldSet(tif, FIELD_TILEDIMENSIONS)) { |
| - tif->tif_dir.td_nstrips = TIFFNumberOfStrips(tif); |
| - tif->tif_dir.td_tilewidth = tif->tif_dir.td_imagewidth; |
| - tif->tif_dir.td_tilelength = tif->tif_dir.td_rowsperstrip; |
| - tif->tif_dir.td_tiledepth = tif->tif_dir.td_imagedepth; |
| - tif->tif_flags &= ~TIFF_ISTILED; |
| - } else { |
| - tif->tif_dir.td_nstrips = TIFFNumberOfTiles(tif); |
| - tif->tif_flags |= TIFF_ISTILED; |
| - } |
| - if (!tif->tif_dir.td_nstrips) { |
| - TIFFErrorExt(tif->tif_clientdata, module, |
| - "Cannot handle zero number of %s", |
| - isTiled(tif) ? "tiles" : "strips"); |
| - goto bad; |
| - } |
| - if (tif->tif_dir.td_nstrips > INT_MAX) { |
| - TIFFErrorExt(tif->tif_clientdata, module, |
| - "Cannot handle %u number of %s", |
| - tif->tif_dir.td_nstrips, |
| - isTiled(tif) ? "tiles" : "strips"); |
| - goto bad; |
| - } |
| - tif->tif_dir.td_stripsperimage = tif->tif_dir.td_nstrips; |
| - if (tif->tif_dir.td_planarconfig == PLANARCONFIG_SEPARATE) |
| - tif->tif_dir.td_stripsperimage /= tif->tif_dir.td_samplesperpixel; |
| - if (!TIFFFieldSet(tif, FIELD_STRIPOFFSETS)) { |
| -#ifdef OJPEG_SUPPORT |
| - if ((tif->tif_dir.td_compression==COMPRESSION_OJPEG) && |
| - (isTiled(tif)==0) && |
| - (tif->tif_dir.td_nstrips==1)) { |
| - /* |
| - * XXX: OJPEG hack. |
| - * If a) compression is OJPEG, b) it's not a tiled TIFF, |
| - * and c) the number of strips is 1, |
| - * then we tolerate the absence of stripoffsets tag, |
| - * because, presumably, all required data is in the |
| - * JpegInterchangeFormat stream. |
| - */ |
| - TIFFSetFieldBit(tif, FIELD_STRIPOFFSETS); |
| - } else |
| -#endif |
| - { |
| - MissingRequired(tif, |
| - isTiled(tif) ? "TileOffsets" : "StripOffsets"); |
| - goto bad; |
| - } |
| - } |
| + |
| /* |
| * Second pass: extract other information. |
| */ |
| @@ -4051,41 +4001,6 @@ TIFFReadDirectory(TIFF* tif) |
| } /* -- if (!dp->tdir_ignore) */ |
| } /* -- for-loop -- */ |
| |
| - if( tif->tif_mode == O_RDWR && |
| - tif->tif_dir.td_stripoffset_entry.tdir_tag != 0 && |
| - tif->tif_dir.td_stripoffset_entry.tdir_count == 0 && |
| - tif->tif_dir.td_stripoffset_entry.tdir_type == 0 && |
| - tif->tif_dir.td_stripoffset_entry.tdir_offset.toff_long8 == 0 && |
| - tif->tif_dir.td_stripbytecount_entry.tdir_tag != 0 && |
| - tif->tif_dir.td_stripbytecount_entry.tdir_count == 0 && |
| - tif->tif_dir.td_stripbytecount_entry.tdir_type == 0 && |
| - tif->tif_dir.td_stripbytecount_entry.tdir_offset.toff_long8 == 0 ) |
| - { |
| - /* Directory typically created with TIFFDeferStrileArrayWriting() */ |
| - TIFFSetupStrips(tif); |
| - } |
| - else if( !(tif->tif_flags&TIFF_DEFERSTRILELOAD) ) |
| - { |
| - if( tif->tif_dir.td_stripoffset_entry.tdir_tag != 0 ) |
| - { |
| - if (!TIFFFetchStripThing(tif,&(tif->tif_dir.td_stripoffset_entry), |
| - tif->tif_dir.td_nstrips, |
| - &tif->tif_dir.td_stripoffset_p)) |
| - { |
| - goto bad; |
| - } |
| - } |
| - if( tif->tif_dir.td_stripbytecount_entry.tdir_tag != 0 ) |
| - { |
| - if (!TIFFFetchStripThing(tif,&(tif->tif_dir.td_stripbytecount_entry), |
| - tif->tif_dir.td_nstrips, |
| - &tif->tif_dir.td_stripbytecount_p)) |
| - { |
| - goto bad; |
| - } |
| - } |
| - } |
| - |
| /* |
| * OJPEG hack: |
| * - If a) compression is OJPEG, and b) photometric tag is missing, |
| @@ -4156,6 +4071,95 @@ TIFFReadDirectory(TIFF* tif) |
| } |
| } |
| |
| + /* |
| + * Setup appropriate structures (by strip or by tile) |
| + * We do that only after the above OJPEG hack which alters SamplesPerPixel |
| + * and thus influences the number of strips in the separate planarconfig. |
| + */ |
| + if (!TIFFFieldSet(tif, FIELD_TILEDIMENSIONS)) { |
| + tif->tif_dir.td_nstrips = TIFFNumberOfStrips(tif); |
| + tif->tif_dir.td_tilewidth = tif->tif_dir.td_imagewidth; |
| + tif->tif_dir.td_tilelength = tif->tif_dir.td_rowsperstrip; |
| + tif->tif_dir.td_tiledepth = tif->tif_dir.td_imagedepth; |
| + tif->tif_flags &= ~TIFF_ISTILED; |
| + } else { |
| + tif->tif_dir.td_nstrips = TIFFNumberOfTiles(tif); |
| + tif->tif_flags |= TIFF_ISTILED; |
| + } |
| + if (!tif->tif_dir.td_nstrips) { |
| + TIFFErrorExt(tif->tif_clientdata, module, |
| + "Cannot handle zero number of %s", |
| + isTiled(tif) ? "tiles" : "strips"); |
| + goto bad; |
| + } |
| + if (tif->tif_dir.td_nstrips > INT_MAX) { |
| + TIFFErrorExt(tif->tif_clientdata, module, |
| + "Cannot handle %u number of %s", |
| + tif->tif_dir.td_nstrips, |
| + isTiled(tif) ? "tiles" : "strips"); |
| + goto bad; |
| + } |
| + tif->tif_dir.td_stripsperimage = tif->tif_dir.td_nstrips; |
| + if (tif->tif_dir.td_planarconfig == PLANARCONFIG_SEPARATE) |
| + tif->tif_dir.td_stripsperimage /= tif->tif_dir.td_samplesperpixel; |
| + if (!TIFFFieldSet(tif, FIELD_STRIPOFFSETS)) { |
| +#ifdef OJPEG_SUPPORT |
| + if ((tif->tif_dir.td_compression==COMPRESSION_OJPEG) && |
| + (isTiled(tif)==0) && |
| + (tif->tif_dir.td_nstrips==1)) { |
| + /* |
| + * XXX: OJPEG hack. |
| + * If a) compression is OJPEG, b) it's not a tiled TIFF, |
| + * and c) the number of strips is 1, |
| + * then we tolerate the absence of stripoffsets tag, |
| + * because, presumably, all required data is in the |
| + * JpegInterchangeFormat stream. |
| + */ |
| + TIFFSetFieldBit(tif, FIELD_STRIPOFFSETS); |
| + } else |
| +#endif |
| + { |
| + MissingRequired(tif, |
| + isTiled(tif) ? "TileOffsets" : "StripOffsets"); |
| + goto bad; |
| + } |
| + } |
| + |
| + if( tif->tif_mode == O_RDWR && |
| + tif->tif_dir.td_stripoffset_entry.tdir_tag != 0 && |
| + tif->tif_dir.td_stripoffset_entry.tdir_count == 0 && |
| + tif->tif_dir.td_stripoffset_entry.tdir_type == 0 && |
| + tif->tif_dir.td_stripoffset_entry.tdir_offset.toff_long8 == 0 && |
| + tif->tif_dir.td_stripbytecount_entry.tdir_tag != 0 && |
| + tif->tif_dir.td_stripbytecount_entry.tdir_count == 0 && |
| + tif->tif_dir.td_stripbytecount_entry.tdir_type == 0 && |
| + tif->tif_dir.td_stripbytecount_entry.tdir_offset.toff_long8 == 0 ) |
| + { |
| + /* Directory typically created with TIFFDeferStrileArrayWriting() */ |
| + TIFFSetupStrips(tif); |
| + } |
| + else if( !(tif->tif_flags&TIFF_DEFERSTRILELOAD) ) |
| + { |
| + if( tif->tif_dir.td_stripoffset_entry.tdir_tag != 0 ) |
| + { |
| + if (!TIFFFetchStripThing(tif,&(tif->tif_dir.td_stripoffset_entry), |
| + tif->tif_dir.td_nstrips, |
| + &tif->tif_dir.td_stripoffset_p)) |
| + { |
| + goto bad; |
| + } |
| + } |
| + if( tif->tif_dir.td_stripbytecount_entry.tdir_tag != 0 ) |
| + { |
| + if (!TIFFFetchStripThing(tif,&(tif->tif_dir.td_stripbytecount_entry), |
| + tif->tif_dir.td_nstrips, |
| + &tif->tif_dir.td_stripbytecount_p)) |
| + { |
| + goto bad; |
| + } |
| + } |
| + } |
| + |
| /* |
| * Make sure all non-color channels are extrasamples. |
| * If it's not the case, define them as such. |