OpenImageIO/oiio — pull request #984 by lgritz (2014-10-31 06:31:27+00:00)
Title: ImageCache: Zero out the SIMD padding in tile allocations!!!

The texture system tries to use SIMD (SSE) ops. It wants work on four
floats at a time. If there aren't four channels, that's ok, because
we'll zero out "past the end" channels by multiplying with a float mask
that will be 0. We also pad the end of the allocation for a tile, so if
we retrieve four values (for a texture with < 4 channels) from the last
pixel in the tile, we don't want to run off the end of the allocation
and segfault.

OK, but if it turns out that this padded but uninitialized memory past
the last pixel of the tile happens to have the bit pattern that
corresponds to NaN, then even though it will get multiplied by a mask
such as (1.0, 1.0, 1.0, 0.0), 0*NaN = NaN, *not* 0! (For any non-NaN
value, the float multiply mask trick would work fine.) So this was
allowing NaNs to creap into the texture results. Oops.

The solution is really simple, which is just to use memset to make sure
the padding at the end of the tile allocation is filled with zero
values.