Skip to content

Commit 05516a0

Browse files
authored
Merge pull request OSGeo#11966 from rouault/tiff_write_multithreaded_read_fresh_file
GTiff: fix 3.10.1 regression when reading a file just created in …
2 parents f51a639 + bcbe4c9 commit 05516a0

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed
Binary file not shown.

autotest/gcore/tiff_read.py

+37
Original file line numberDiff line numberDiff line change
@@ -5582,3 +5582,40 @@ def test_tiff_read_corrupted_lzw():
55825582
ds = gdal.Open("data/gtiff/lzw_corrupted.tif")
55835583
with pytest.raises(Exception):
55845584
ds.ReadRaster()
5585+
5586+
5587+
###############################################################################
5588+
# Test bugfix for https://lists.osgeo.org/pipermail/gdal-dev/2025-March/060378.html
5589+
5590+
5591+
@gdaltest.enable_exceptions()
5592+
def test_tiff_read_multithreaded_read_fresh_file(tmp_vsimem):
5593+
5594+
drv = gdal.GetDriverByName("GTiff")
5595+
ds_out = drv.Create(
5596+
tmp_vsimem / "temp.tif",
5597+
xsize=100,
5598+
ysize=100,
5599+
bands=1,
5600+
eType=gdal.GDT_Byte,
5601+
options=["COMPRESS=DEFLATE", "NUM_THREADS=2"],
5602+
)
5603+
assert ds_out.ReadRaster(0, 0, 100, 100) == b"\x00" * (100 * 100)
5604+
5605+
5606+
###############################################################################
5607+
# Test bugfix for https://lists.osgeo.org/pipermail/gdal-dev/2025-March/060378.html
5608+
5609+
5610+
@gdaltest.enable_exceptions()
5611+
def test_tiff_read_multithreaded_read_missing_tilebytecounts_and_offsets():
5612+
5613+
ds = gdal.OpenEx(
5614+
"data/gtiff/missing_tilebytecounts_and_offsets.tif",
5615+
open_options=["NUM_THREADS=2"],
5616+
)
5617+
with pytest.raises(
5618+
Exception,
5619+
match="missing_tilebytecounts_and_offsets.tif: Error while getting location of block 0",
5620+
):
5621+
ds.ReadRaster()

frmts/gtiff/gtiffdataset.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,18 @@ bool GTiffDataset::IsBlockAvailable(int nBlockId, vsi_l_offset *pnOffset,
777777
return bytecount != 0;
778778
}
779779

780+
if (!m_bCrystalized)
781+
{
782+
// If this is a fresh new file not yet crystalized, do not try to
783+
// read the [Strip|Tile][ByteCounts|Offsets] tags as they do not yet
784+
// exist. Trying would set *pbErrOccurred=true, which is not desirable.
785+
if (pnOffset)
786+
*pnOffset = 0;
787+
if (pnSize)
788+
*pnSize = 0;
789+
return false;
790+
}
791+
780792
toff_t *panByteCounts = nullptr;
781793
toff_t *panOffsets = nullptr;
782794
const bool bIsTiled = CPL_TO_BOOL(TIFFIsTiled(m_hTIFF));

frmts/gtiff/gtiffdataset_read.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,9 @@ CPLErr GTiffDataset::MultiThreadedRead(int nXOff, int nYOff, int nXSize,
13171317
}
13181318
if (bErrorInIsBlockAvailable)
13191319
{
1320+
ReportError(CE_Failure, CPLE_AppDefined,
1321+
"Error while getting location of block %d",
1322+
nBlockId);
13201323
std::lock_guard<std::recursive_mutex> oLock(
13211324
sContext.oMutex);
13221325
sContext.bSuccess = false;

0 commit comments

Comments
 (0)