Skip to content

Commit 1982b6f

Browse files
committed
Fix bad pointer math
In SSE, we were incrementing a pointer as if it were a uint16_t, not an si128, causing out of bounds accesses on non-block aligned chunks. Similarly, simplify the alignment logic and check return values and pointers in related accesses (non-block aligned linear lut lookup). Signed-off-by: Kimball Thurston <kdt3rd@gmail.com>
1 parent 2df7802 commit 1982b6f

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

src/lib/OpenEXRCore/internal_dwa_compressor.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,7 @@ DwaCompressor_uncompress (
854854
if (version > 2) { return EXR_ERR_BAD_CHUNK_LEADER; }
855855

856856
rv = DwaCompressor_setupChannelData (me);
857+
if (rv != EXR_ERR_SUCCESS) { return rv; }
857858

858859
//
859860
// Uncompress the UNKNOWN data into _planarUncBuffer[UNKNOWN]
@@ -1079,6 +1080,8 @@ DwaCompressor_uncompress (
10791080
packedAcBufferEnd += decoder._packedAcCount * sizeof (uint16_t);
10801081

10811082
packedDcBufferEnd += decoder._packedDcCount * sizeof (uint16_t);
1083+
1084+
totalAcUncompressedCount -= decoder._packedAcCount;
10821085
totalDcUncompressedCount -= decoder._packedDcCount;
10831086

10841087
me->_channelData[rChan].processed = 1;
@@ -1101,6 +1104,12 @@ DwaCompressor_uncompress (
11011104

11021105
if (cd->processed) continue;
11031106

1107+
if (chan->width == 0 || chan->height == 0)
1108+
{
1109+
cd->processed = 1;
1110+
continue;
1111+
}
1112+
11041113
switch (cd->compression)
11051114
{
11061115
case LOSSY_DCT:
@@ -1138,6 +1147,7 @@ DwaCompressor_uncompress (
11381147
packedDcBufferEnd +=
11391148
(size_t) decoder._packedDcCount * sizeof (uint16_t);
11401149

1150+
totalAcUncompressedCount -= decoder._packedAcCount;
11411151
totalDcUncompressedCount -= decoder._packedDcCount;
11421152
if (rv != EXR_ERR_SUCCESS) { return rv; }
11431153
}

src/lib/OpenEXRCore/internal_dwa_decoder.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -320,19 +320,12 @@ LossyDctDecoder_execute (
320320
// Allocate a temp aligned buffer to hold a rows worth of full
321321
// 8x8 half-float blocks
322322
//
323-
324323
rowBlockHandle = alloc_fn (
325324
(size_t) numComp * (size_t) numBlocksX * 64 * sizeof (uint16_t) +
326325
_SSE_ALIGNMENT);
327326
if (!rowBlockHandle) return EXR_ERR_OUT_OF_MEMORY;
328327

329-
rowBlock[0] = (uint16_t*) rowBlockHandle;
330-
331-
for (int i = 0; i < _SSE_ALIGNMENT; ++i)
332-
{
333-
if (((uintptr_t) (rowBlockHandle + i) & _SSE_ALIGNMENT_MASK) == 0)
334-
rowBlock[0] = (uint16_t*) (rowBlockHandle + i);
335-
}
328+
rowBlock[0] = (uint16_t*) simd_align_pointer (rowBlockHandle);
336329

337330
for (int comp = 1; comp < numComp; ++comp)
338331
rowBlock[comp] = rowBlock[comp - 1] + numBlocksX * 64;
@@ -649,8 +642,8 @@ LossyDctDecoder_execute (
649642
{
650643
_mm_storeu_si128 (dst, _mm_loadu_si128 (src));
651644

652-
src += 8 * 8;
653-
dst += 8;
645+
++dst;
646+
src += 8;
654647
}
655648
}
656649
}
@@ -720,9 +713,16 @@ LossyDctDecoder_execute (
720713

721714
dst += 8 * numFullBlocksX;
722715

723-
for (int x = 0; x < maxX; ++x)
716+
if (d->_toLinear)
717+
{
718+
for (int x = 0; x < maxX; ++x)
719+
{
720+
*dst++ = d->_toLinear[*src++];
721+
}
722+
}
723+
else
724724
{
725-
*dst++ = d->_toLinear[*src++];
725+
memcpy (dst, src, maxX * sizeof(uint16_t));
726726
}
727727
}
728728
}

src/lib/OpenEXRCore/internal_dwa_simd.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ __extension__ extern __inline float32x4x2_t
6868
}
6969
#endif
7070

71+
static inline uint8_t *simd_align_pointer (uint8_t* ptr)
72+
{
73+
return ptr +
74+
((_SSE_ALIGNMENT - (((uintptr_t)ptr) & _SSE_ALIGNMENT_MASK)) &
75+
_SSE_ALIGNMENT_MASK);
76+
}
77+
78+
7179
//
7280
// Color space conversion, Inverse 709 CSC, Y'CbCr -> R'G'B'
7381
//

0 commit comments

Comments
 (0)