From 1758db799b915292e01fb513c85a013562266792 Mon Sep 17 00:00:00 2001 From: Larry Gritz Date: Fri, 8 Jun 2012 17:43:56 -0700 Subject: [PATCH 1/2] Fix allocation and stride bugs in ImageInput::read_tiles. When reading tiled images, where the image is not a whole number of tiles, this bug could misallocate and run off the end of the buffer while dealing with the partial tiles on the right or bottom edge of the image. --- src/libOpenImageIO/imageinput.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/libOpenImageIO/imageinput.cpp b/src/libOpenImageIO/imageinput.cpp index f63ab45de1..bf0f222811 100644 --- a/src/libOpenImageIO/imageinput.cpp +++ b/src/libOpenImageIO/imageinput.cpp @@ -444,6 +444,9 @@ ImageInput::read_tiles (int xbegin, int xend, int ybegin, int yend, : (format.size() * nchans); stride_t full_pixelsize = native_data ? m_spec.pixel_bytes(true) : (format.size() * m_spec.nchannels); + stride_t full_tilewidthbytes = full_pixelsize * m_spec.tile_width; + stride_t full_tilewhbytes = full_tilewidthbytes * m_spec.tile_height; + stride_t full_tilebytes = full_tilewhbytes * m_spec.tile_depth; size_t prefix_bytes = m_spec.pixel_bytes (0,firstchan,true); std::vector buf; for (int z = zbegin; z < zend; z += std::max(1,m_spec.tile_depth)) { @@ -464,16 +467,14 @@ ImageInput::read_tiles (int xbegin, int xend, int ybegin, int yend, ok &= read_tile (x, y, z, format, tilestart, xstride, ystride, zstride); } else { - buf.resize (m_spec.tile_bytes()); + buf.resize (full_tilebytes); ok &= read_tile (x, y, z, format, &buf[0], - full_pixelsize, - full_pixelsize*m_spec.tile_width, - full_pixelsize*m_spec.tile_pixels()); + full_pixelsize, full_tilewidthbytes, + full_tilewhbytes); if (ok) copy_image (nchans, xw, yh, zd, &buf[prefix_bytes], pixelsize, full_pixelsize, - full_pixelsize*m_spec.tile_width, - full_pixelsize*m_spec.tile_pixels(), + full_tilewidthbytes, full_tilewhbytes, tilestart, xstride, ystride, zstride); } tilestart += m_spec.tile_width * xstride; From c9018e121272aa3d6bd9516ae8e0b7a303aff803 Mon Sep 17 00:00:00 2001 From: Larry Gritz Date: Mon, 11 Jun 2012 15:55:30 -0700 Subject: [PATCH 2/2] Fix stride bugs for files with different data formats per channel. --- src/libOpenImageIO/imageinput.cpp | 4 ++-- src/libtexture/imagecache.cpp | 2 ++ testsuite/openexr-suite/ref/out.txt | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libOpenImageIO/imageinput.cpp b/src/libOpenImageIO/imageinput.cpp index bf0f222811..3ec308b0d2 100644 --- a/src/libOpenImageIO/imageinput.cpp +++ b/src/libOpenImageIO/imageinput.cpp @@ -232,8 +232,8 @@ ImageInput::read_scanlines (int ybegin, int yend, int z, TypeDesc chanformat = m_spec.channelformats[c+firstchan]; ok = convert_image (1 /* channels */, m_spec.width, nscanlines, 1, &buf[offset], chanformat, - pixel_bytes, AutoStride, AutoStride, - (char *)data + c*m_spec.format.size(), + native_pixel_bytes, native_scanline_bytes, 0, + (char *)data + c*format.size(), format, xstride, ystride, zstride); offset += chanformat.size (); } diff --git a/src/libtexture/imagecache.cpp b/src/libtexture/imagecache.cpp index f25217039a..f4fead0190 100644 --- a/src/libtexture/imagecache.cpp +++ b/src/libtexture/imagecache.cpp @@ -415,6 +415,8 @@ ImageCacheFile::open (ImageCachePerThreadInfo *thread_info) invalidate_spec (); return false; } + // ImageCache can't store differing formats per channel + tempspec.channelformats.clear(); LevelInfo levelinfo (tempspec, nativespec); si.levels.push_back (levelinfo); ++nmip; diff --git a/testsuite/openexr-suite/ref/out.txt b/testsuite/openexr-suite/ref/out.txt index 463b637981..75b3da2975 100644 --- a/testsuite/openexr-suite/ref/out.txt +++ b/testsuite/openexr-suite/ref/out.txt @@ -66,7 +66,7 @@ Comparing "../../../../../openexr-images-1.5.0/ScanLines/Tree.exr" and "Tree.exr PASS Reading ../../../../../openexr-images-1.5.0/ScanLines/Blobbies.exr ../../../../../openexr-images-1.5.0/ScanLines/Blobbies.exr : 1040 x 1040, 5 channel, half/half/half/half/float openexr - SHA-1: 1D3D059692BB2074264393AA2B04D3E60DC52BDC + SHA-1: 64C3C765E0D40AA92E066F6EC9198A8053BF1179 channel list: R (half), G (half), B (half), A (half), Z (float) pixel data origin: x=-20, y=-20 full/display size: 1000 x 1000