]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix the error handling in bytesio_sizeof(). (GH-10459)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 1 Jun 2019 21:58:33 +0000 (14:58 -0700)
committerGitHub <noreply@github.com>
Sat, 1 Jun 2019 21:58:33 +0000 (14:58 -0700)
bytesio_sizeof() must check if an error has occurred in _PySys_GetSizeOf().
(cherry picked from commit 36dcaab7fde5d2e54cdeff5b705b5adcb27726dd)

Co-authored-by: Zackery Spytz <zspytz@gmail.com>
Modules/_io/bytesio.c

index e4d637cc3aeaa2caa6f03b28238f54274bb1ba92..8501f42ed80097843127ee6e00458e65da5dbb5e 100644 (file)
@@ -942,8 +942,13 @@ bytesio_sizeof(bytesio *self, void *unused)
     Py_ssize_t res;
 
     res = _PyObject_SIZE(Py_TYPE(self));
-    if (self->buf && !SHARED_BUF(self))
-        res += _PySys_GetSizeOf(self->buf);
+    if (self->buf && !SHARED_BUF(self)) {
+        Py_ssize_t s = _PySys_GetSizeOf(self->buf);
+        if (s == -1) {
+            return NULL;
+        }
+        res += s;
+    }
     return PyLong_FromSsize_t(res);
 }