Skip to content

Commit 7728325

Browse files
committed
[image output] Initialize pixels of partial tile conversion buffer.
When writing a partial tile, the unused pixels still go through float conversion. This means, that floating point operations are done on uninitialized data. This can easily lead to NaN and to floating point exceptions, if those were to be enabled. This change will set the shared buffer used for all partial tiles to all zero pixels. Tested by running valgrind before and after the change FIXES: #4461 Signed-off-by: Bram Stolk <b.stolk@gmail.com>
1 parent f875327 commit 7728325

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/libOpenImageIO/imageoutput.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,14 @@ ImageOutput::write_tiles(int xbegin, int xend, int ybegin, int yend, int zbegin,
177177
ok &= write_tile(x, y, z, format, tilestart, xstride,
178178
ystride, zstride);
179179
} else {
180-
if (!buf.get())
181-
buf.reset(new char[pixelsize * m_spec.tile_pixels()]);
180+
if (!buf.get()) {
181+
const size_t sz = pixelsize * m_spec.tile_pixels();
182+
char* mem = new char[sz];
183+
// Not all pixels will be initialized, so we set them to zero here.
184+
// This will avoid generation of NaN, FPEs and valgrind errors.
185+
memset(mem, 0, sz);
186+
buf.reset(mem);
187+
}
182188
OIIO::copy_image(m_spec.nchannels, xw, yh, zd, tilestart,
183189
pixelsize, xstride, ystride, zstride,
184190
&buf[0], pixelsize,

0 commit comments

Comments
 (0)