Skip to content

Guard against two DoS crashes: parser recursion depth and integer div/mod by zero - #92

Open
stratomarco wants to merge 1 commit into
google:mainfrom
stratomarco:fix-dos-recursion-divzero
Open

Guard against two DoS crashes: parser recursion depth and integer div/mod by zero#92
stratomarco wants to merge 1 commit into
google:mainfrom
stratomarco:fix-dos-recursion-divzero

Conversation

@stratomarco

Copy link
Copy Markdown

Add a recursion depth cap in Parser::parseExpression. Deeply-nested expressions
previously recursed through the expression-precedence chain without bound and
exhausted the stack (SIGSEGV at parse time). jinja2 guards recursion here.

Guard integer division and modulo against a zero divisor at all sites (the
BinaryOpExpr evaluation switch and the Value operators). Previously {{ 1/0 }},
{{ 5//0 }} or {{ x%0 }} crashed with SIGFPE at render time.

Both throw std::runtime_error, consistent with existing error handling. Verified
against 239 real chat templates (unchanged) and normal arithmetic
(1+2*3=7, 10%3=1, 8/2=4). Found via coverage-guided fuzzing."

…/mod by zero

Add a recursion depth cap in Parser::parseExpression. Deeply-nested expressions
previously recursed through the expression-precedence chain without bound and
exhausted the stack (SIGSEGV at parse time). jinja2 guards recursion here.

Guard integer division and modulo against a zero divisor at all sites (the
BinaryOpExpr evaluation switch and the Value operators). Previously {{ 1/0 }},
{{ 5//0 }} or {{ x%0 }} crashed with SIGFPE at render time.

Both throw std::runtime_error, consistent with existing error handling. Verified
against 239 real chat templates (unchanged) and normal arithmetic
(1+2*3=7, 10%3=1, 8/2=4). Found via coverage-guided fuzzing.
@google-cla

google-cla Bot commented Aug 14, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant