Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ba5c743

Browse files
committed
Issue 5449: Fix io.BytesIO to not accept arbitrary keywords
Patch contributed by Erick Tryzelaar.
1 parent bbffb25 commit ba5c743

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

Lib/test/test_memoryio.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,11 @@ def test_bytes_array(self):
461461
self.assertEqual(memio.write(a), 10)
462462
self.assertEqual(memio.getvalue(), buf)
463463

464+
def test_issue5449(self):
465+
buf = self.buftype("1234567890")
466+
self.ioclass(initial_bytes=buf)
467+
self.assertRaises(TypeError, self.ioclass, buf, foo=None)
468+
464469

465470
class TextIOTestMixin:
466471

Modules/_io/bytesio.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,9 +759,11 @@ bytesio_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
759759
static int
760760
bytesio_init(bytesio *self, PyObject *args, PyObject *kwds)
761761
{
762+
char *kwlist[] = {"initial_bytes", NULL};
762763
PyObject *initvalue = NULL;
763764

764-
if (!PyArg_ParseTuple(args, "|O:BytesIO", &initvalue))
765+
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:BytesIO", kwlist,
766+
&initvalue))
765767
return -1;
766768

767769
/* In case, __init__ is called multiple times. */

0 commit comments

Comments
 (0)