From 75c3d6ff092f67d1c5aff1d05fcdef1ef1a5bae3 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Fri, 13 Feb 2009 11:01:07 +0000 Subject: [PATCH] #3694: fix an "XXX undetected error" leak in struct. --- Lib/test/test_struct.py | 4 ++++ Modules/_struct.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py index 2bc92f3b39..3d5e028728 100644 --- a/Lib/test/test_struct.py +++ b/Lib/test/test_struct.py @@ -524,6 +524,10 @@ class StructTest(unittest.TestCase): self.assertRaises(struct.error, s.pack_into, small_buf, 0, test_string) self.assertRaises(struct.error, s.pack_into, small_buf, 2, test_string) + # Test bogus offset (issue 3694) + sb = small_buf + self.assertRaises(TypeError, struct.pack_into, b'1', sb, None) + def test_pack_into_fn(self): test_string = b'Reykjavik rocks, eow!' writable_buf = array.array('b', b' '*100) diff --git a/Modules/_struct.c b/Modules/_struct.c index 94cb303679..57441c4338 100644 --- a/Modules/_struct.c +++ b/Modules/_struct.c @@ -1785,7 +1785,7 @@ s_pack_into(PyObject *self, PyObject *args) assert( buffer_len >= 0 ); /* Extract the offset from the first argument */ - offset = PyLong_AsSsize_t(PyTuple_GET_ITEM(args, 1)); + offset = PyNumber_AsSsize_t(PyTuple_GET_ITEM(args, 1), PyExc_IndexError); if (offset == -1 && PyErr_Occurred()) return NULL; -- 2.40.0