Skip to content

Commit 8cfd0c0

Browse files
committed
Harden overflow checks before _PyBytes_Resize in compile.c
1 parent 5e30ba1 commit 8cfd0c0

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Python/compile.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6605,9 +6605,14 @@ static int
66056605
assemble_emit_linetable_pair(struct assembler *a, int bdelta, int ldelta)
66066606
{
66076607
Py_ssize_t len = PyBytes_GET_SIZE(a->a_lnotab);
6608-
if (a->a_lnotab_off + 2 >= len) {
6609-
if (_PyBytes_Resize(&a->a_lnotab, len * 2) < 0)
6608+
if (a->a_lnotab_off >= len - 2) {
6609+
if (len > PY_SSIZE_T_MAX / 2) {
6610+
PyErr_NoMemory();
6611+
return 0;
6612+
}
6613+
if (_PyBytes_Resize(&a->a_lnotab, len * 2) < 0) {
66106614
return 0;
6615+
}
66116616
}
66126617
unsigned char *lnotab = (unsigned char *) PyBytes_AS_STRING(a->a_lnotab);
66136618
lnotab += a->a_lnotab_off;

0 commit comments

Comments
 (0)