fix(cypher): bound UNWIND literal-list buffer to prevent stack overflow#1173
Open
SEPURI-SAI-KRISHNA wants to merge 1 commit into
Open
fix(cypher): bound UNWIND literal-list buffer to prevent stack overflow#1173SEPURI-SAI-KRISHNA wants to merge 1 commit into
SEPURI-SAI-KRISHNA wants to merge 1 commit into
Conversation
…ck overflow Signed-off-by: SEPURI-SAI-KRISHNA <saik20533@gmail.com>
SEPURI-SAI-KRISHNA
force-pushed
the
fix/cypher-unwind-stack-overflow
branch
from
July 19, 2026 06:27
ffc88cc to
d0457f2
Compare
Owner
|
Thanks for the reproduce-first memory-safety fix. Triage is complete: this is a high-priority |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes a stack out-of-bounds write (CWE-787) in the Cypher
UNWINDliteral-listparser (
parse_unwind_clause,src/cypher/cypher.c).When assembling a literal list into the fixed 2 KB stack buffer
char buf[CBM_SZ_2K], the code advances the write cursor by the return value ofsnprintf:snprintfreturns the number of bytes it would have written, so a singleoversized element pushes
blenpastsizeof(buf). The trailing writes are thenunguarded:
and on multi-element lists the next iteration's
sizeof(buf) - blenunderflowsto a huge
size_t, lettingsnprintfwrite far past the buffer.The query string is agent-controlled through the MCP
querytool, and Cypherstring literals lex up to
CBM_SZ_4K - 1(4095) chars with no length cap beforeparsing, so
UNWIND ["<~3000 chars>"] AS x MATCH (n) RETURN nreaches theoverflow.
Reproduced first (UBSan, before the fix):
The fix clamps
blenafter everysnprintfand guards the rawbuf[blen++]stores — the same pattern already used by the sibling functionformat_collect_list(), which builds an identical JSON array into aCBM_SZ_2Kbuffer and was already hardened. After the fix all 161 cypher testspass with zero sanitizer errors.
Two regression tests are added (both fail under UBSan without the fix):
cypher_parse_unwind_oversized_literal_no_overflow— single oversized elementcypher_parse_unwind_many_elements_no_overflow— many elements accumulating past 2 KBChecklist
git commit -s) — required, CI rejectsunsigned commits (DCO, see CONTRIBUTING.md)
make -f Makefile.cbm test)make -f Makefile.cbm lint-ci)