Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6fb9090

Browse files
committed
Issue #1621: Avoid signed int negation overflow in audioop
1 parent e3d7474 commit 6fb9090

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Core and Builtins
2626
Library
2727
-------
2828

29+
- Issue #1621: Avoid signed int negation overflow in the "audioop" module.
30+
2931
- Issue #27533: Release GIL in nt._isdir
3032

3133
- Issue #17711: Fixed unpickling by the persistent ID with protocol 0.

Modules/audioop.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,9 @@ audioop_max_impl(PyObject *module, Py_buffer *fragment, int width)
446446
return NULL;
447447
for (i = 0; i < fragment->len; i += width) {
448448
int val = GETRAWSAMPLE(width, fragment->buf, i);
449-
if (val < 0) absval = (-val);
449+
/* Cast to unsigned before negating. Unsigned overflow is well-
450+
defined, but signed overflow is not. */
451+
if (val < 0) absval = -(unsigned int)val;
450452
else absval = val;
451453
if (absval > max) max = absval;
452454
}

0 commit comments

Comments
 (0)