fix(extract): guard against large SQL file stack overflow (#691)#698
fix(extract): guard against large SQL file stack overflow (#691)#698lg320531124 wants to merge 1 commit into
Conversation
3875a72 to
0b83cfb
Compare
|
Huge thanks for opening this PR and for the work you put into it. The maintainer shop is currently full, so this may sit for a bit before it gets a proper review. We will come back to this as soon as possible with real feedback; I wanted to make sure it did not sit unacknowledged in the meantime. |
…ter parser The tree-sitter SQL grammar (39 MB parser.c) uses deeply recursive non-terminals that overflow the C stack on files with many statements (e.g. schema dumps >10K lines, stored procedures). The stack overflow kills the thread before any timeout callback can fire, so we must reject the file *before* calling ts_parser_parse_with_options(). Add a pre-parse line-count guard (CBM_SQL_MAX_LINES = 5000) in cbm_extract_file() that returns has_error for SQL files exceeding the threshold, allowing the indexing pipeline to skip gracefully rather than crash. Fixes DeusData#691 Signed-off-by: lg320531124 <lg320531124@users.noreply.github.com>
0b83cfb to
e8db9e5
Compare
|
Thank you @lg320531124 — you're right that a large After analysis we're not going to take the line-count cap, because line count is the wrong signal for this crash: a recursive/GLR parser overflows on depth, not size — a 20-line but thousands-deep-nested statement still crashes and sails under 5000 lines, while a legitimately large-but-flat 6000-line migration parses fine and would be dropped by this cap. It happens to stop the one reported schema dump, but by coincidence (that file being both big and a real crasher), not by addressing the mechanism. Instead we've planned a proper, general fix (reproduce-first): (1) root-cause the actual tree-sitter SQL crash and fix it at the grammar/scanner level so it stops crashing on all platforms; and (2) a general resilience layer so that any file that fails during indexing — any language, parse or LSP — is skipped-and-reported (per-run logfile + surfaced via MCP/CLI) instead of aborting the run, with a cross-platform process supervisor so a hard crash can never take the whole run down. That resolves #668 and the whole class of similar issues. Closing this in favor of that effort — genuinely appreciate the report and the push on it. 🙏 |
Summary
The tree-sitter SQL grammar (39 MB
parser.c) uses deeply recursive non-terminals that overflow the C stack on files with many statements (e.g. schema dumps >10K lines, stored procedures). The stack overflow kills the thread before any timeout callback can fire, so a pre-parse guard is the only safe mitigation.Changes
CBM_SQL_MAX_LINES = 5000) incbm_extract_file()that returnshas_errorfor SQL files exceeding the thresholdWhy line-count, not byte-size?
CREATE TABLElines overflows the default 512KB macOS thread stackWhy 5000 lines?
Why in
cbm_extract_file(), not the discover layer?Testing
has_error=trueFixes #691
Related: #668 (original report)