Add PSHR32_ovflw() and use it in IMDCT

Prevents integer overflow UB in the shift rounding when the signal blows
up on bad bitstreams (if it triggers, the signal was already unusable
anyway).
This commit is contained in:
Jean-Marc Valin 2025-03-21 16:22:09 -04:00
parent fba923d83a
commit edffe56b30
No known key found for this signature in database
GPG key ID: 8D2952BBB52C646D
4 changed files with 10 additions and 4 deletions

View file

@ -69,6 +69,8 @@ extern opus_int64 celt_mips;
/* Avoid MSVC warning C4146: unary minus operator applied to unsigned type */
/** Negate 32-bit value, ignore any overflows */
#define NEG32_ovflw(a) (celt_mips+=2,(opus_val32)(0-(opus_uint32)(a)))
/** 32-bit arithmetic shift right with rounding-to-nearest, ignoring overflows */
#define PSHR32_ovflw(a,shift) (SHR32(ADD32_ovflw(a, (EXTEND32(1)<<(shift)>>1)),shift))
static OPUS_INLINE short NEG16(int x)
{