Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: race condition in TIFF reader #3772

Merged
merged 3 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/libtexture/imagecache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,7 @@ ImageCacheFile::read_tile(ImageCachePerThreadInfo* thread_info,
}
}
if (!ok) {
m_broken = true;
std::string err = inp->geterror();
if (errors_should_issue()) {
imagecache().error("{}",
Expand Down
9 changes: 6 additions & 3 deletions src/tiff.imageio/tiffinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2253,8 +2253,9 @@ TIFFInput::read_native_tiles(int subimage, int miplevel, int xbegin, int xend,
// xbegin, xend, ybegin, yend, zbegin, zend);
size_t tileidx = 0;
for (int z = zbegin; z < zend; z += m_spec.tile_depth) {
for (int y = ybegin; y < yend; y += m_spec.tile_height) {
for (int x = xbegin; x < xend; x += m_spec.tile_width, ++tileidx) {
for (int y = ybegin; ok && y < yend; y += m_spec.tile_height) {
for (int x = xbegin; ok && x < xend;
x += m_spec.tile_width, ++tileidx) {
char* cbuf = compressed_scratch.get() + tileidx * cbound;
char* ubuf = scratch.get() + tileidx * tile_bytes;
auto csize = TIFFReadRawTile(m_tif, tile_index(x, y, z), cbuf,
Expand All @@ -2264,7 +2265,8 @@ TIFFInput::read_native_tiles(int subimage, int miplevel, int xbegin, int xend,
errorfmt(
"TIFFReadRawTile failed reading tile x={},y={},z={}: {}",
x, y, z, err.size() ? err.c_str() : "unknown error");
return false;
ok = false;
break;
}
// Push the rest of the work onto the thread pool queue
auto out = this;
Expand All @@ -2289,6 +2291,7 @@ TIFFInput::read_native_tiles(int subimage, int miplevel, int xbegin, int xend,
}
}
}
tasks.wait();
return ok;
}

Expand Down
4 changes: 3 additions & 1 deletion testsuite/tiff-misc/ref/out-libtiff403.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Full command line was:
> oiiotool --oiioattrib try_all_readers 0 --info -v src/crash-1633.tif
oiiotool ERROR: read : File does not exist: "src/crash-1643.tif"
Full command line was:
> oiiotool --oiioattrib try_all_readers 0 --info -v src/crash-1643.tif
> oiiotool --oiioattrib try_all_readers 0 --info src/crash-1643.tif -o out.exr
iconvert ERROR copying "src/crash-1709.tif" to "crash-1709.exr" :
Decoding error at scanline 0, incorrect header check
Comparing "check1.tif" and "ref/check1.tif"
PASS
29 changes: 29 additions & 0 deletions testsuite/tiff-misc/ref/out-libtiff410.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Reading src/separate.tif
src/separate.tif : 128 x 128, 3 channel, uint8 tiff
SHA-1: 486088DECAE711C444FDCAB009C378F7783AD9C5
channel list: R, G, B
compression: "zip"
DateTime: "2020:10:25 15:32:04"
Orientation: 1 (normal)
planarconfig: "separate"
Software: "OpenImageIO 2.3.0dev : oiiotool --pattern fill:topleft=0,0,0:topright=1,0,0:bottomleft=0,1,0:bottomright=1,1,1 128x128 3 --planarconfig separate -scanline -attrib tiff:rowsperstrip 17 -d uint8 -o separate.tif"
oiio:BitsPerSample: 8
tiff:Compression: 8
tiff:PhotometricInterpretation: 2
tiff:PlanarConfiguration: 2
tiff:RowsPerStrip: 7
Comparing "src/separate.tif" and "separate.tif"
PASS
oiiotool ERROR: read : No support for data format of "src/corrupt1.tif"
Full command line was:
> oiiotool --oiioattrib try_all_readers 0 --info -v src/corrupt1.tif
oiiotool ERROR: read : File does not exist: "src/crash-1633.tif"
Full command line was:
> oiiotool --oiioattrib try_all_readers 0 --info -v src/crash-1633.tif
oiiotool ERROR: read : File does not exist: "src/crash-1643.tif"
Full command line was:
> oiiotool --oiioattrib try_all_readers 0 --info src/crash-1643.tif -o out.exr
iconvert ERROR copying "src/crash-1709.tif" to "crash-1709.exr" :
Decoding error at scanline 0, incorrect header check
Comparing "check1.tif" and "ref/check1.tif"
PASS
4 changes: 3 additions & 1 deletion testsuite/tiff-misc/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Full command line was:
> oiiotool --oiioattrib try_all_readers 0 --info -v src/crash-1633.tif
oiiotool ERROR: read : File does not exist: "src/crash-1643.tif"
Full command line was:
> oiiotool --oiioattrib try_all_readers 0 --info -v src/crash-1643.tif
> oiiotool --oiioattrib try_all_readers 0 --info src/crash-1643.tif -o out.exr
iconvert ERROR copying "src/crash-1709.tif" to "crash-1709.exr" :

Comparing "check1.tif" and "ref/check1.tif"
PASS
3 changes: 2 additions & 1 deletion testsuite/tiff-misc/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# Test bugs we had until OIIO 2.4 for these corrupt file
command += oiiotool ("--oiioattrib try_all_readers 0 --info -v src/corrupt1.tif", failureok = True)
command += oiiotool ("--oiioattrib try_all_readers 0 --info -v src/crash-1633.tif", failureok = True)
command += oiiotool ("--oiioattrib try_all_readers 0 --info -v src/crash-1643.tif", failureok = True)
command += oiiotool ("--oiioattrib try_all_readers 0 --info src/crash-1643.tif -o out.exr", failureok = True)
command += iconvert ("src/crash-1709.tif crash-1709.exr", failureok=True)

outputs = [ "check1.tif", "out.txt" ]
Binary file added testsuite/tiff-misc/src/crash-1709.tif
Binary file not shown.