Skip to content

Commit

Permalink
fix(ImageInput): Initialize pixels of partial tile conversion buffer. (
Browse files Browse the repository at this point in the history
…#4462)

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 <[email protected]>
  • Loading branch information
stolk authored Sep 30, 2024
1 parent 609999e commit 970153d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/libOpenImageIO/imageoutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,13 @@ ImageOutput::write_tiles(int xbegin, int xend, int ybegin, int yend, int zbegin,
ok &= write_tile(x, y, z, format, tilestart, xstride,
ystride, zstride);
} else {
if (!buf.get())
buf.reset(new char[pixelsize * m_spec.tile_pixels()]);
if (!buf.get()) {
const size_t sz = pixelsize * m_spec.tile_pixels();
buf.reset(new char[sz]);
// Not all pixels will be initialized, so we set them to zero here.
// This will avoid generation of NaN, FPEs and valgrind errors.
memset(buf.get(), 0, sz);
}
OIIO::copy_image(m_spec.nchannels, xw, yh, zd, tilestart,
pixelsize, xstride, ystride, zstride,
&buf[0], pixelsize,
Expand Down

0 comments on commit 970153d

Please sign in to comment.