Skip to content

Commit

Permalink
[image output] Initialize pixels of partial tile conversion buffer.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
stolk committed Sep 29, 2024
1 parent f875327 commit 7728325
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/libOpenImageIO/imageoutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,14 @@ 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();
char* mem = 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(mem, 0, sz);
buf.reset(mem);
}
OIIO::copy_image(m_spec.nchannels, xw, yh, zd, tilestart,
pixelsize, xstride, ystride, zstride,
&buf[0], pixelsize,
Expand Down

0 comments on commit 7728325

Please sign in to comment.