Skip to content

Commit 75c3d6f

Browse files
committed
#3694: fix an "XXX undetected error" leak in struct.
1 parent c8dcfb6 commit 75c3d6f

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

Lib/test/test_struct.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,10 @@ def test_pack_into(self):
524524
self.assertRaises(struct.error, s.pack_into, small_buf, 0, test_string)
525525
self.assertRaises(struct.error, s.pack_into, small_buf, 2, test_string)
526526

527+
# Test bogus offset (issue 3694)
528+
sb = small_buf
529+
self.assertRaises(TypeError, struct.pack_into, b'1', sb, None)
530+
527531
def test_pack_into_fn(self):
528532
test_string = b'Reykjavik rocks, eow!'
529533
writable_buf = array.array('b', b' '*100)

Modules/_struct.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1785,7 +1785,7 @@ s_pack_into(PyObject *self, PyObject *args)
17851785
assert( buffer_len >= 0 );
17861786

17871787
/* Extract the offset from the first argument */
1788-
offset = PyLong_AsSsize_t(PyTuple_GET_ITEM(args, 1));
1788+
offset = PyNumber_AsSsize_t(PyTuple_GET_ITEM(args, 1), PyExc_IndexError);
17891789
if (offset == -1 && PyErr_Occurred())
17901790
return NULL;
17911791

0 commit comments

Comments
 (0)