[Python-checkins] cpython: Issue #1621: Avoid signed int negation overflow in audioop
martin.panter
python-checkins at python.org
Mon Jul 18 23:09:13 EDT 2016
https://hg.python.org/cpython/rev/d6a86018ab33
changeset: 102404:d6a86018ab33
user: Martin Panter <vadmium+py at gmail.com>
date: Tue Jul 19 03:05:42 2016 +0000
summary:
Issue #1621: Avoid signed int negation overflow in audioop
files:
Misc/NEWS | 2 ++
Modules/audioop.c | 4 +++-
2 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -26,6 +26,8 @@
Library
-------
+- Issue #1621: Avoid signed int negation overflow in the "audioop" module.
+
- Issue #27533: Release GIL in nt._isdir
- Issue #17711: Fixed unpickling by the persistent ID with protocol 0.
diff --git a/Modules/audioop.c b/Modules/audioop.c
--- a/Modules/audioop.c
+++ b/Modules/audioop.c
@@ -446,7 +446,9 @@
return NULL;
for (i = 0; i < fragment->len; i += width) {
int val = GETRAWSAMPLE(width, fragment->buf, i);
- if (val < 0) absval = (-val);
+ /* Cast to unsigned before negating. Unsigned overflow is well-
+ defined, but signed overflow is not. */
+ if (val < 0) absval = -(unsigned int)val;
else absval = val;
if (absval > max) max = absval;
}
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list