Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
gh-153569: Avoid overflow when sizing implicit line flags
  • Loading branch information
pablogsal committed Sep 5, 2026
commit 27c3d732c3d375d9d133782038984b2da7647da7
7 changes: 3 additions & 4 deletions Parser/tokenizer/source.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ _PyTok_SourceDiscard(_PyTok_SourceText *source)
source->bytes[0] = '\0';
}
if (source->implicit_lines != NULL) {
memset(source->implicit_lines, 0,
Py_MIN(((Py_ssize_t)source->nlines + 7) / 8,
source->implicit_cap));
Py_ssize_t used = source->nlines / 8 + (source->nlines % 8 != 0);
memset(source->implicit_lines, 0, Py_MIN(used, source->implicit_cap));
}
source->nlines = 0;
}
Expand Down Expand Up @@ -106,7 +105,7 @@ reserve_checkpoints(_PyTok_SourceText *source, int needed)
static int
reserve_implicit_lines(_PyTok_SourceText *source, int nlines)
{
Py_ssize_t needed = ((Py_ssize_t)nlines + 7) / 8;
Py_ssize_t needed = nlines / 8 + (nlines % 8 != 0);
if (needed <= source->implicit_cap) {
return 0;
}
Expand Down