Skip to content

Commit

Permalink
LIBERTIFF: do not crash on corrupted LZW compressed file
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Jan 7, 2025
1 parent 1646133 commit 6e21ecc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
Binary file added autotest/gcore/data/gtiff/lzw_corrupted.tif
Binary file not shown.
7 changes: 7 additions & 0 deletions autotest/gcore/libertiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,3 +859,10 @@ def test_libertiff_read_geomatrix():
def test_libertiff_num_threads_saturated():

libertiff_open("data/byte.tif", open_options=["NUM_THREADS=10000"])


def test_libertiff_corrupted_lzw():

ds = libertiff_open("data/gtiff/lzw_corrupted.tif")
with pytest.raises(Exception):
ds.ReadRaster()
7 changes: 7 additions & 0 deletions autotest/gcore/tiff_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -5575,3 +5575,10 @@ def test_tiff_read_corrupted_vat_dbf(tmp_vsimem):
band = ds.GetRasterBand(1)
with pytest.raises(Exception):
band.GetDefaultRAT()


def test_tiff_read_corrupted_lzw():

ds = gdal.Open("data/gtiff/lzw_corrupted.tif")
with pytest.raises(Exception):
ds.ReadRaster()
2 changes: 2 additions & 0 deletions frmts/libertiff/libertiffdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1403,6 +1403,8 @@ bool LIBERTIFFDataset::ReadBlock(GByte *pabyBlockData, int nBlockXOff,

if (tlsState.m_tiff.tif_decodestrip)
{
tlsState.m_tiff.tif_name =
const_cast<char *>(GetDescription());
tlsState.m_tiff.tif_dir.td_sampleformat =
static_cast<uint16_t>(m_image->sampleFormat());
tlsState.m_tiff.tif_dir.td_bitspersample =
Expand Down

0 comments on commit 6e21ecc

Please sign in to comment.