speex icon indicating copy to clipboard operation
speex copied to clipboard

Undefined behavior / float-cast-overflow in speex_decode_stereo_int

Open dklimkin opened this issue 1 year ago • 5 comments

speex_decode_stereo_int:276-277

      data[2*i] = (spx_int16_t)MULT16_16_P14(stereo->smooth_left, tmp);
      data[2*i+1] = (spx_int16_t)MULT16_16_P14(stereo->smooth_right, tmp);

casts float to 16 bit int which can cause an overflow and UB. This UB typically results in SIGILL with clang.

dklimkin avatar Jul 08 '24 09:07 dklimkin

Hello @tmatth, i made PR #28 to fix this

Dutchman101 avatar Feb 17 '25 11:02 Dutchman101

speex_decode_stereo_int:276-277

      data[2*i] = (spx_int16_t)MULT16_16_P14(stereo->smooth_left, tmp);
      data[2*i+1] = (spx_int16_t)MULT16_16_P14(stereo->smooth_right, tmp);

casts float to 16 bit int which can cause an overflow and UB. This UB typically results in SIGILL with clang.

Do you have a POC? Also I'm assuming you're talking about the inside of the MULT16_16_P14 calls and not the spx_int16_t casts of the results which should be fine.

tmatth avatar Feb 17 '25 14:02 tmatth

Hello @tmatth, i made PR #28 to fix this

Thanks I'll review there, although this is just avoiding undefined behavior in the fixed-debug builds so I don't see how that would fix this issue.

tmatth avatar Feb 17 '25 14:02 tmatth

Hello @tmatth, i made PR #28 to fix this

Thanks I'll review there, although this is just avoiding undefined behavior in the fixed-debug builds so I don't see how that would fix this issue.

@tmatth

MULT16_16_P14 is created in fixed_debug, so i figured that's where to fix it. Am i wrong?

Also, now that i have your attention, would you please take a look at what i feel may be a critical security bug? PR #29: Fix OOB

Dutchman101 avatar Feb 17 '25 21:02 Dutchman101

MULT16_16_P14 is created in fixed_debug, so i figured that's where to fix it. Am i wrong?

That's the version that gets used if you ./configure --enable-fixed-point-debug (only really used when debugging). The version defined in fixed_generic also needs to be fixed (as that is what will be used by normal fixed-point builds).

tmatth avatar Feb 21 '25 18:02 tmatth