]> granicus.if.org Git - python/commitdiff
Fix the error handling in bytesio_sizeof(). (GH-10459)
authorZackery Spytz <zspytz@gmail.com>
Sat, 1 Jun 2019 21:07:46 +0000 (15:07 -0600)
committerSerhiy Storchaka <storchaka@gmail.com>
Sat, 1 Jun 2019 21:07:45 +0000 (00:07 +0300)
bytesio_sizeof() must check if an error has occurred in _PySys_GetSizeOf().

Modules/_io/bytesio.c

index 32427e44de5b1c338912b0c48543ae5ceda87c6a..19e1ed8441e3f325179cca15e6bf162e389f96ac 100644 (file)
@@ -943,8 +943,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);
 }