Skip to content

Commit 419546f

Browse files
authored
Merge branch 'main' into dev-reload
2 parents c60cad5 + 149c465 commit 419546f

4 files changed

Lines changed: 8 additions & 1 deletion

File tree

.github/workflows/new-bugs-announce-notifier.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
// We need to truncate the body size, because the max size for
4545
// the whole payload is 16kb. We want to be safe and assume that
4646
// body can take up to ~8kb of space.
47-
body : issue.data.body.substring(0, 8000)
47+
body : (issue.data.body || "").substring(0, 8000)
4848
};
4949
5050
const data = {

Lib/test/test_struct.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,8 @@ def test_operations_on_half_initialized_Struct(self):
836836
self.assertRaises(RuntimeError, S.unpack, spam)
837837
self.assertRaises(RuntimeError, S.unpack_from, spam)
838838
self.assertRaises(RuntimeError, getattr, S, 'format')
839+
self.assertRaises(RuntimeError, S.__sizeof__)
840+
self.assertRaises(RuntimeError, repr, S)
839841
self.assertEqual(S.size, -1)
840842

841843

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix crash in :mod:`struct` when calling :func:`repr` or
2+
``__sizeof__()`` on an uninitialized :class:`struct.Struct`
3+
object created via ``Struct.__new__()`` without calling ``__init__()``.

Modules/_struct.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2382,6 +2382,7 @@ static PyObject *
23822382
Struct___sizeof___impl(PyStructObject *self)
23832383
/*[clinic end generated code: output=2d0d78900b4cdb4e input=faca5925c1f1ffd0]*/
23842384
{
2385+
ENSURE_STRUCT_IS_READY(self);
23852386
size_t size = _PyObject_SIZE(Py_TYPE(self)) + sizeof(formatcode);
23862387
for (formatcode *code = self->s_codes; code->fmtdef != NULL; code++) {
23872388
size += sizeof(formatcode);
@@ -2393,6 +2394,7 @@ static PyObject *
23932394
s_repr(PyObject *op)
23942395
{
23952396
PyStructObject *self = PyStructObject_CAST(op);
2397+
ENSURE_STRUCT_IS_READY(self);
23962398
PyObject* fmt = PyUnicode_FromStringAndSize(
23972399
PyBytes_AS_STRING(self->s_format), PyBytes_GET_SIZE(self->s_format));
23982400
if (fmt == NULL) {

0 commit comments

Comments
 (0)