[Python-checkins] Fix the error handling in bytesio_sizeof(). (GH-10459)

Miss Islington (bot) webhook-mailer at python.org
Sat Jun 1 17:58:37 EDT 2019


https://github.com/python/cpython/commit/fefdc009906c5ea8fb57383817b3c42d3b0634ad
commit: fefdc009906c5ea8fb57383817b3c42d3b0634ad
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019-06-01T14:58:33-07:00
summary:

Fix the error handling in bytesio_sizeof(). (GH-10459)


bytesio_sizeof() must check if an error has occurred in _PySys_GetSizeOf().
(cherry picked from commit 36dcaab7fde5d2e54cdeff5b705b5adcb27726dd)

Co-authored-by: Zackery Spytz <zspytz at gmail.com>

files:
M Modules/_io/bytesio.c

diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c
index e4d637cc3aea..8501f42ed800 100644
--- a/Modules/_io/bytesio.c
+++ b/Modules/_io/bytesio.c
@@ -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);
 }
 



More information about the Python-checkins mailing list