Commit Graph

3229 Commits

Author SHA1 Message Date
Nikola Forró
e897442344 tools/tiffcp.c: fix potential division by zero
Signed-off-by: Nikola Forró <nforro@redhat.com>
2019-06-12 12:23:33 +02:00
Even Rouault
91480d3d3c Merge branch 'defer_strile_writing' into 'master'
Add TIFFDeferStrileArrayWriting() and TIFFForceStrileArrayWriting()

See merge request libtiff/libtiff!82
2019-05-29 20:11:57 +00:00
Even Rouault
9cf3a97bea Merge branch 'TIFFReadFromUserBuffer' into 'master'
Add TIFFReadFromUserBuffer()

See merge request libtiff/libtiff!81
2019-05-29 20:11:43 +00:00
Even Rouault
f273e83262
Fix vulnerability in 'D' (DeferStrileLoad) mode (master only) (fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=14908) 2019-05-26 11:33:47 +02:00
Even Rouault
cc84dc7409
Replace 'stripped' by 'striped' in error messages 2019-05-25 13:46:50 +02:00
Even Rouault
eaeca6274a
Add TIFFDeferStrileArrayWriting() and TIFFForceStrileArrayWriting()
Those advanced writing functions must be used in a particular sequence
to make their intended effect. Their aim is to control when/where
the [Strip/Tile][Offsets/ByteCounts] arrays are written into the file.

The purpose of this is to generate 'cloud-optimized geotiff' files where
the first KB of the file only contain the IFD entries without the potentially
large strile arrays. Those are written afterwards.

The typical sequence of calls is:
TIFFOpen()
[ TIFFCreateDirectory(tif) ]
Set fields with calls to TIFFSetField(tif, ...)
TIFFDeferStrileArrayWriting(tif)
TIFFWriteCheck(tif, ...)
 TIFFWriteDirectory(tif)
 ... potentially create other directories and come back to the above directory
TIFFForceStrileArrayWriting(tif): emit the arrays at the end of file

See test/defer_strile_writing.c for a practical example.
2019-05-25 11:37:34 +02:00
Even Rouault
0f797bf386
Fix vulnerability introduced by defer strile loading (master only)
Found on GDAL with https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=14894
Disabling the TIFF_DEFERSTRILELOAD bit in ChopupStripArray() was a
bad idea since when using TIFFReadDirectory() to reload the directory again
would lead to a different value of td_rowsperstrip, which could confuse
readers if they relied on the value found initially.
2019-05-24 11:20:27 +02:00
Even Rouault
fdec42f217
Fix typo in error message (master only) 2019-05-24 10:34:39 +02:00
Even Rouault
4e74734ded
Add TIFFReadFromUserBuffer()
This function replaces the use of TIFFReadEncodedStrip()/TIFFReadEncodedTile()
when the user can provide the buffer for the input data, for example when
he wants to avoid libtiff to read the strile offset/count values from the
[Strip|Tile][Offsets/ByteCounts] array.
2019-05-23 00:38:59 +02:00
Even Rouault
06337fdcfd
libtiff.def: add missing new symbols 2019-05-22 22:57:41 +02:00
Even Rouault
d2e2b4eeac
test/defer_strile_loading.c: fix warning with Visual C++ 2019-05-22 22:34:27 +02:00
Even Rouault
f017d2fae3
_TIFFRewriteField(): fix for bigtiff case (master only)
116cf67f4c made StripByteCount/TileByteCount to
always be rewritten as TIFF_LONG8.
2019-05-22 21:55:01 +02:00
Even Rouault
ef82728f44 Merge branch 'ondemand_strile_offbytecount_loading' into 'master'
Make defer strile offset/bytecount loading available at runtime

See merge request libtiff/libtiff!79
2019-05-21 13:46:23 +00:00
Even Rouault
57bc1126ba Merge branch 'bigtiff_write_bytecount_on_long_when_possible' into 'master'
Create TileByteCounts/StripByteCounts tag with SHORT (ClassicTIFF/BigTIFF) or  LONG (BigTIFF) type when possible

See merge request libtiff/libtiff!78
2019-05-21 13:46:03 +00:00
Even Rouault
d0ec0aeab6 Merge branch 'html_link' into 'master'
libtiff.html, bigtiffpr.html: absolute => relative link

See merge request libtiff/libtiff!80
2019-05-21 13:45:33 +00:00
Thomas Bernard
02c16a3e2e
libtiff.html, bigtiffpr.html: absolute => relative link 2019-05-14 20:05:13 +02:00
Even Rouault
371ad2658c
Make defer strile offset/bytecount loading available at runtime
... and add per-strile offset/bytecount loading capabilities.

Part of this commit makes the behaviour that was previously met when
libtiff was compiled with -DDEFER_STRILE_LOAD available for default builds
when specifying the new 'D' (Deferred) TIFFOpen() flag. In that mode, the [Tile/Strip][ByteCounts/Offsets]
arrays are only loaded when first accessed. This can speed-up the opening
of files stored on the network when just metadata retrieval is needed.
This mode has been used for years by the GDAL library when compiled with
its embeded libtiff copy.

To avoid potential out-of-tree code (typically codecs) that would use
the td_stripbytecount and td_stripoffset array inconditionnaly assuming they
have been loaded, those have been suffixed with _p (for protected). The
use of the new functions mentionned below is then recommended.

Another addition of this commit is the capability of loading only the
values of the offset/bytecount of the strile of interest instead of the
whole array. This is enabled with the new 'O' (Ondemand) flag of TIFFOpen()
(which implies 'D'). That behaviour has also been used by GDAL, which hacked
into the td_stripoffset/td_stripbytecount arrays directly. The new code
added in the _TIFFFetchStrileValue() and _TIFFPartialReadStripArray() internal
functions is mostly a port of what was in GDAL GTiff driver previously.

Related to that, the public TIFFGetStrileOffset[WithErr]() and TIFFGetStrileByteCount[WithErr]()
functions have been added to API. They are of particular interest when
using sparse files (with offset == bytecount == 0) and you want to detect
if a strile is present or not without decompressing the data, or updating
an existing sparse file.
They will also be used to enable a future enhancement where client code can entirely
skip bytecount loading in some situtations

A new test/defer_strile_loading.c test has been added to test the above
capabilities.
2019-05-10 14:46:45 +02:00
Even Rouault
458c211ae2
Creation: use SHORT type when possible for StripByteCounts/TileByteCounts
This follows the same logic as previous commit.
2019-05-10 11:08:01 +02:00
Even Rouault
116cf67f4c
BigTIFF creation: write TileByteCounts/StripByteCounts tag with LONG when possible
In most situations of BigTIFF file, the tile/strip sizes are of reasonable size,
that is they fit on a 4-byte LONG. So in that case, use LONG instead of LONG8
to save some space. For uncompressed file, it is easy to detect such situations
by checking at the TIFFTileSize64()/TIFFStripSize64() return. For compressed file,
we must take into account the fact that compression may sometimes result in
larger compressed data. So we allow this optimization only for a few select
compression times, and take a huge security margin (10x factor). We also only
apply this optimization on multi-strip files, so as to allow easy on-the-fly
growing of single-strip files whose strip size could grow above the 4GB threshold.

This change is compatible with the BigTIFF specification. According to
https://www.awaresystems.be/imaging/tiff/bigtiff.html:
"The StripOffsets, StripByteCounts, TileOffsets, and TileByteCounts tags are
allowed to have the datatype TIFF_LONG8 in BigTIFF. Old datatypes TIFF_LONG,
and TIFF_SHORT where allowed in the TIFF 6.0 specification, are still valid in BigTIFF, too. "
On a practical point of view, this is also compatible on reading/writing of
older libtiff 4.X versions.

The only glitch I found, which is rather minor, is when using such a BigTIFF
file with TileByteCounts/StripByteCounts written with TIFF_LONG, and updating
it with an older libtiff 4.X version with a change in the
[Tile/Strip][ByteCounts/Offsets] array. In that case the _TIFFRewriteField()
function will rewrite the directory and array with TIFF_LONG8, instead of updating
the existing array (this is an issue fixed by this commit). The file will
still be valid however, hence the minor severity of this.
2019-05-09 22:47:15 +02:00
Even Rouault
b9b93f661e Merge branch 'bug2799' into 'master'
fix fax2tiff

See merge request libtiff/libtiff!55
2019-05-08 08:36:34 +00:00
Even Rouault
9acff86b56 Merge branch 'bug_2829' into 'master'
WIN32: use tif_win32.c when building with CMake

See merge request libtiff/libtiff!75
2019-05-08 08:16:38 +00:00
Even Rouault
2f8bd01315 Merge branch 'FILESOURCE_SCENETYPE_reading' into 'master'
Reading error for FileSource and SceneType tags corrected.

See merge request libtiff/libtiff!76
2019-05-06 19:32:13 +00:00
Su Laus
ca75b773c9 Reading error for FileSource and SceneType tags corrected.
EXIF tags FILESOURCE and SCENETYPE are defined as TIFF_UNDEFINED and field_readcount==1!
There is a bug in TIFFReadDirEntryByte() preventing to read correctly type TIFF_UNDEFINED fields with field_readcount==1
Upgrade of TIFFReadDirEntryByte() with added TIFF_UNDEFINED switch-entry allows libtiff to read those tags correctly.
2019-05-06 19:32:13 +00:00
Thomas Bernard
59eb35172f
WIN32: use tif_win32.c when building with CMake
see http://bugzilla.maptools.org/show_bug.cgi?id=2829

the top CMakeLists.txt defines
win32_io and USE_WIN32_FILEIO

WIN32_IO is defined nowhere in CMake (only in automake things)
2019-04-25 14:35:51 +02:00
Even Rouault
453be8a9ce Merge branch 'gitlab_pages' into 'master'
Advertise https://libtiff.gitlab.io/libtiff/ as mirror

See merge request libtiff/libtiff!70
2019-04-25 10:25:58 +00:00
Even Rouault
3c0becb4aa Merge branch 'bug_2844' into 'master'
tiff2ps.c: PSDataColorContig(): avoid heap buffer overrun

See merge request libtiff/libtiff!69
2019-04-25 09:39:01 +00:00
Even Rouault
db77de50bc Merge branch 'issue_2785' into 'master'
tiff2pdf.c: don't call t2p_tile_collapse_left() for Ycbcr

See merge request libtiff/libtiff!64
2019-04-25 09:37:26 +00:00
Even Rouault
c824479e4c Merge branch 'fix_gdal_1439' into 'master'
TIFFWriteEncodedStrip/TIFFWriteEncodedTile: fix rewriting of LZW-compressed data

See merge request libtiff/libtiff!74
2019-04-11 19:12:56 +00:00
Even Rouault
0f88612e3e
TIFFWriteEncodedStrip/TIFFWriteEncodedTile: fix rewriting of LZW-compressed data
Fixes https://github.com/OSGeo/gdal/issues/1439

When rewriting a LZW tile/strip whose existing size is very close to a multiple of
1024 bytes (and larger than 8192 bytes) with compressed data that is larger,
the new data was not placed at the end of the file, causing corruption.
2019-04-11 21:00:56 +02:00
Even Rouault
f9fc01c331 Merge branch 'bug2848' into 'master'
tif_luv.c: LogLuvSetupEncode() error must return 0

See merge request libtiff/libtiff!72
2019-04-08 08:18:30 +00:00
Thomas Bernard
a18ef87a5a
build/gitlab-ci: fix typo 2019-04-03 14:56:33 +02:00
Thomas Bernard
cce0a85e6f
show test-suite.log in gitlab-ci
useful when build fails
2019-04-03 14:55:46 +02:00
Thomas Bernard
57c112bfa9
Add output check for tiff2ps
note : the reference files have been generated in master branch
2019-04-03 14:55:29 +02:00
Even Rouault
bf35895107
tif_read.c: potentially fix false positive from Coverity Scan. CID 1400288 2019-03-23 11:31:10 +01:00
Even Rouault
12ae83914e
tif_read.c: potentially fix false positive from Coverity Scan. CID 1400271 2019-03-23 11:30:18 +01:00
Even Rouault
b6b2f1ff5b
tif_zip.c: remove dead code. CID 1400360 2019-03-23 11:25:44 +01:00
Even Rouault
301463dacf
tif_webp.c: remove false positive warning about dereference before null check. CID 1400255 2019-03-23 11:24:50 +01:00
Even Rouault
f4b7eb7cd3
tif_pixarlog.c: remove dead code. CID 1400342 2019-03-23 11:21:24 +01:00
Even Rouault
c12b6a2a39
tif_pixarlog.c: avoid false positive Coverity Scan warnings about overflow. CID 1400300 and 1400367 2019-03-23 11:20:18 +01:00
Even Rouault
d0358fdbc3
tif_lzw.c: silence CoverityScan false positive. CID 1400355 2019-03-23 11:16:22 +01:00
Even Rouault
07f939bf59
tif_luv.c: silence CoverityScan false positive. CID 1400231, 1400251, 1400254, 1400272, 1400318, 1400356 2019-03-23 11:09:42 +01:00
Even Rouault
dd2dfe1d6a
TryChopUpUncompressedBigTiff(): avoid potential division by zero. master only. GDAL Coverity CID 1400263 2019-03-23 11:05:49 +01:00
Thomas Bernard
1fb9e731ef
tif_luv.c: LogLuvSetupEncode() error must return 0
see http://bugzilla.maptools.org/show_bug.cgi?id=2848

if wrongly returning 1, the processing of incorrect file continues,
which causes problems.
2019-03-22 12:17:28 +01:00
Thomas Bernard
933575f505
add a test for fax2tiff tool 2019-03-22 10:06:01 +01:00
Thomas Bernard
ea2e933b17
tiff2pdf.c: don't call t2p_tile_collapse_left() when buffer size is wrong
see http://bugzilla.maptools.org/show_bug.cgi?id=2785
2019-02-28 13:44:49 +01:00
Thomas Bernard
9a926b2d89
Advertise https://libtiff.gitlab.io/libtiff/ as mirror
I'm put it above the maptools.org mirror because
Even Rouault believe at some point it will be completely removed
2019-02-28 13:32:27 +01:00
Even Rouault
e3d738277b Merge branch 'bug_2826' into 'master'
tiff2pdf.c: check colormap pointers when loading CMYK with colormap

See merge request libtiff/libtiff!65
2019-02-28 12:30:20 +00:00
Thomas Bernard
b7d479cf8b
tiff2pdf.c: check colormap pointers
Avoid access to non initialized pointers
http://bugzilla.maptools.org/show_bug.cgi?id=2826
2019-02-28 13:05:19 +01:00
Even Rouault
621b54a0b5 Merge branch 'fix_warnings' into 'master'
tiff2ps.c: fix warning caused by integer promotion

See merge request libtiff/libtiff!68
2019-02-27 21:00:33 +00:00
Thomas Bernard
05029fb7f1
PSDataColorContig(): avoid heap buffer overrun
fixes http://bugzilla.maptools.org/show_bug.cgi?id=2844
each iteration of the loop read nc bytes
2019-02-24 00:50:12 +01:00