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

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."

@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.

stratomarco added a commit to stratomarco/mapfuzz that referenced this pull request Sep 4, 2026
…oth are in public PR google/minja#92 (open, CLA-blocked since 2026-08-14), not embargoed; 0004 recursion independently disclosed publicly by another researcher (public prior art, not novel); note llama.cpp migrating off minja; fix stale PRIVATE_findings refs to the public PR URL; drop 'reproducer withheld' framing contradicted by the open PR
…/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.
@stratomarco
stratomarco force-pushed the fix-dos-recursion-divzero branch from 050a23d to 28c9e15 Compare September 4, 2026 23:27
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