Skip to content

jinja: fix a bug that empty expressions can trigger null binding in jinja parser (#20911)#20913

Merged
CISC merged 5 commits intoggml-org:masterfrom
zeph1912:master
Mar 30, 2026
Merged

jinja: fix a bug that empty expressions can trigger null binding in jinja parser (#20911)#20913
CISC merged 5 commits intoggml-org:masterfrom
zeph1912:master

Conversation

@zeph1912
Copy link
Copy Markdown
Contributor

Overview

This is to fix the bug found by UndefinedBehaviorSanitizer in jinja parser. The patch will reject empty computed member expressions before returning slices[0] from parse_member_expression_arguments().

Requirements

@zeph1912 zeph1912 requested a review from CISC as a code owner March 23, 2026 17:52
@github-actions github-actions Bot added the jinja parser Issues related to the jinja parser label Mar 23, 2026
Copy link
Copy Markdown
Member

@CISC CISC left a comment

Choose a reason for hiding this comment

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

Please add a test so we can verify parity.

Comment thread common/jinja/parser.cpp Outdated
@CISC CISC linked an issue Mar 23, 2026 that may be closed by this pull request
@CISC
Copy link
Copy Markdown
Member

CISC commented Mar 27, 2026

@zeph1912 gentle ping

Treat empty computed member expressions like `a[]` as undefined instead of
raising a parser error, to match Jinja2 behavior.

- return a noop expression for empty computed member arguments
- return undefined when a computed member key evaluates to undefined
- add Jinja tests covering `a[]|default('fallback')` and `a[] is undefined`
@zeph1912 zeph1912 requested a review from ggerganov as a code owner March 29, 2026 04:10
@github-actions github-actions Bot added the testing Everything test related label Mar 29, 2026
@zeph1912
Copy link
Copy Markdown
Contributor Author

sorry for the delay, addressed in the new commit

Comment thread common/jinja/runtime.cpp Outdated
Move undefined-property handling to the common member access path, and add a test covering `a[undefined] is undefined`.
Comment thread common/jinja/runtime.cpp Outdated
Comment thread common/jinja/runtime.h Outdated
zeph1912 and others added 2 commits March 30, 2026 08:42
Initialize val and then return it when property is undefined.

Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@scala.com>
@CISC CISC requested a review from ngxson March 30, 2026 15:06
@CISC CISC merged commit ead417f into ggml-org:master Mar 30, 2026
43 of 45 checks passed
slartibardfast pushed a commit to slartibardfast/llama.cpp that referenced this pull request Apr 12, 2026
* Reject empty computed member expressions before returning slices[0] from parse_member_expression_arguments().

* Treat empty computed member expressions with Jinja2 undefined semantics

Treat empty computed member expressions like `a[]` as undefined instead of
raising a parser error, to match Jinja2 behavior.

- return a noop expression for empty computed member arguments
- return undefined when a computed member key evaluates to undefined
- add Jinja tests covering `a[]|default('fallback')` and `a[] is undefined`

* Handle undefined computed member properties

Move undefined-property handling to the common member access path, and add a test covering `a[undefined] is undefined`.

* Use default undefined value in member access

Initialize val and then return it when property is undefined.

Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@scala.com>

* empty statement parses to blank_expression instead of noop_statement

---------

Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@scala.com>
Seunghhon pushed a commit to Seunghhon/llama.cpp that referenced this pull request Apr 26, 2026
* Reject empty computed member expressions before returning slices[0] from parse_member_expression_arguments().

* Treat empty computed member expressions with Jinja2 undefined semantics

Treat empty computed member expressions like `a[]` as undefined instead of
raising a parser error, to match Jinja2 behavior.

- return a noop expression for empty computed member arguments
- return undefined when a computed member key evaluates to undefined
- add Jinja tests covering `a[]|default('fallback')` and `a[] is undefined`

* Handle undefined computed member properties

Move undefined-property handling to the common member access path, and add a test covering `a[undefined] is undefined`.

* Use default undefined value in member access

Initialize val and then return it when property is undefined.

Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@scala.com>

* empty statement parses to blank_expression instead of noop_statement

---------

Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@scala.com>
rsenthilkumar6 pushed a commit to rsenthilkumar6/llama.cpp that referenced this pull request May 1, 2026
* Reject empty computed member expressions before returning slices[0] from parse_member_expression_arguments().

* Treat empty computed member expressions with Jinja2 undefined semantics

Treat empty computed member expressions like `a[]` as undefined instead of
raising a parser error, to match Jinja2 behavior.

- return a noop expression for empty computed member arguments
- return undefined when a computed member key evaluates to undefined
- add Jinja tests covering `a[]|default('fallback')` and `a[] is undefined`

* Handle undefined computed member properties

Move undefined-property handling to the common member access path, and add a test covering `a[undefined] is undefined`.

* Use default undefined value in member access

Initialize val and then return it when property is undefined.

Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@scala.com>

* empty statement parses to blank_expression instead of noop_statement

---------

Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@scala.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

jinja parser Issues related to the jinja parser testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Misc. bug: jinja: null pointer binding in parser

3 participants