Skip to content

gh-160814: Fix out-of-bounds read in the SRE code validator for IN with skip < 2 - #160815

Open
DmitryTD wants to merge 3 commits into
python:mainfrom
DmitryTD:gh-160814-sre-in-skip
Open

DmitryTD wants to merge 3 commits into
python:mainfrom
DmitryTD:gh-160814-sre-in-skip

Conversation

@DmitryTD

@DmitryTD DmitryTD commented Oct 28, 2026 •

Copy link
Copy Markdown

The IN opcode branch of _validate_inner() reads code[skip-2] without checking that skip >= 2. skip is unsigned, so for skip of 0 or 1 the index skip - 2 wraps to a huge value and the read goes out of bounds, crashing the interpreter.

This is reachable only by passing hand-crafted bytecode to _sre.compile(); the public re compiler always emits skip >= 2 for IN.

@python-cla-bot

python-cla-bot Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@sobolevn sobolevn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_sre.compile("x", 0, [13, 0, 1], 0, {}, ()) as a reproducer seems simple enough to test: it must not crash.

@DmitryTD

Copy link
Copy Markdown
Author

Added a test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants