Skip to content

Commit 8792374

Browse files
author
benjamin.peterson
committed
Victor Stinner's patches to check the return result of PyLong_Ssize_t
reviewed by Amaury git-svn-id: http://svn.python.org/projects/python/trunk@66693 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent daa99e2 commit 8792374

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

Modules/_bytesio.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ bytesio_read(BytesIOObject *self, PyObject *args)
221221

222222
if (PyInt_Check(arg)) {
223223
size = PyInt_AsSsize_t(arg);
224+
if (size == -1 && PyErr_Occurred())
225+
return NULL;
224226
}
225227
else if (arg == Py_None) {
226228
/* Read until EOF is reached, by default. */
@@ -288,6 +290,8 @@ bytesio_readline(BytesIOObject *self, PyObject *args)
288290

289291
if (PyInt_Check(arg)) {
290292
size = PyInt_AsSsize_t(arg);
293+
if (size == -1 && PyErr_Occurred())
294+
return NULL;
291295
}
292296
else if (arg == Py_None) {
293297
/* No size limit, by default. */
@@ -332,6 +336,8 @@ bytesio_readlines(BytesIOObject *self, PyObject *args)
332336

333337
if (PyInt_Check(arg)) {
334338
maxsize = PyInt_AsSsize_t(arg);
339+
if (maxsize == -1 && PyErr_Occurred())
340+
return NULL;
335341
}
336342
else if (arg == Py_None) {
337343
/* No size limit, by default. */
@@ -415,6 +421,8 @@ bytesio_truncate(BytesIOObject *self, PyObject *args)
415421

416422
if (PyInt_Check(arg)) {
417423
size = PyInt_AsSsize_t(arg);
424+
if (size == -1 && PyErr_Occurred())
425+
return NULL;
418426
}
419427
else if (arg == Py_None) {
420428
/* Truncate to current position if no argument is passed. */

Modules/_struct.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,6 +1755,8 @@ s_pack_into(PyObject *self, PyObject *args)
17551755

17561756
/* Extract the offset from the first argument */
17571757
offset = PyInt_AsSsize_t(PyTuple_GET_ITEM(args, 1));
1758+
if (offset == -1 && PyErr_Occurred())
1759+
return NULL;
17581760

17591761
/* Support negative offsets. */
17601762
if (offset < 0)

0 commit comments

Comments
 (0)