From 6e21ecc70a8ae9dd007dfa5aa7206995d380ce05 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Tue, 7 Jan 2025 17:26:43 +0100 Subject: [PATCH] LIBERTIFF: do not crash on corrupted LZW compressed file --- autotest/gcore/data/gtiff/lzw_corrupted.tif | Bin 0 -> 163 bytes autotest/gcore/libertiff.py | 7 +++++++ autotest/gcore/tiff_read.py | 7 +++++++ frmts/libertiff/libertiffdataset.cpp | 2 ++ 4 files changed, 16 insertions(+) create mode 100644 autotest/gcore/data/gtiff/lzw_corrupted.tif diff --git a/autotest/gcore/data/gtiff/lzw_corrupted.tif b/autotest/gcore/data/gtiff/lzw_corrupted.tif new file mode 100644 index 0000000000000000000000000000000000000000..444fc94f51227d9d093c1c54c54f6d0d8d7f9841 GIT binary patch literal 163 zcmebD)MDUZU|`^3U|?isU<9(5fS3`=2J@k8kSb;6Jkew?$$HBe8+X7#gJh|NjpF5Mc&t literal 0 HcmV?d00001 diff --git a/autotest/gcore/libertiff.py b/autotest/gcore/libertiff.py index 6d8b535dfcd0..0efbf2b97358 100755 --- a/autotest/gcore/libertiff.py +++ b/autotest/gcore/libertiff.py @@ -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() diff --git a/autotest/gcore/tiff_read.py b/autotest/gcore/tiff_read.py index 500d05398930..763c75c1af8c 100755 --- a/autotest/gcore/tiff_read.py +++ b/autotest/gcore/tiff_read.py @@ -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() diff --git a/frmts/libertiff/libertiffdataset.cpp b/frmts/libertiff/libertiffdataset.cpp index 5b496081fac8..6e88b572423b 100644 --- a/frmts/libertiff/libertiffdataset.cpp +++ b/frmts/libertiff/libertiffdataset.cpp @@ -1403,6 +1403,8 @@ bool LIBERTIFFDataset::ReadBlock(GByte *pabyBlockData, int nBlockXOff, if (tlsState.m_tiff.tif_decodestrip) { + tlsState.m_tiff.tif_name = + const_cast(GetDescription()); tlsState.m_tiff.tif_dir.td_sampleformat = static_cast(m_image->sampleFormat()); tlsState.m_tiff.tif_dir.td_bitspersample =