diff --git a/internal/cbm/vendored/grammars/MANIFEST.md b/internal/cbm/vendored/grammars/MANIFEST.md index e1e907f5e..3e88cdee7 100644 --- a/internal/cbm/vendored/grammars/MANIFEST.md +++ b/internal/cbm/vendored/grammars/MANIFEST.md @@ -124,6 +124,7 @@ row instead. | vbnet | `vbnet/scanner.c`, `scan_xml_literal` (patch file: `tools/tree-sitter-vbnet/patches/xml-literal-tag-syntax.patch`) | inside an element tag, outside a quoted value, accept only name characters, blanks, `=`, quotes, `/>`, `>` and `<%=`; in element text, require `<` to start a tag, closing tag, comment, PI or embedded expression, and `&` to start a reference; otherwise the scan fails | **Quadratic lexing at attribute lines.** CodeGraph's scanner is offered a `<` where a declaration or member starts. There it opens a VB attribute block (` _`), never an XML literal, but the scan took `start_tag);` before `state->start_tag = NULL;` | **Leak (LeakSanitizer, Linux x64; 0e61867d9).** tree-sitter calls deserialize repeatedly during a parse, and each call dropped the previous `start_tag` allocation; freeing it first is safe because create() NULL-initializes it and destroy() frees and NULLs it. Upstream fixed the same leak after our pin in `ee2f84f9b857` (2026-04-24, merged via #361 on 2026-09-19; it also moves the free out of serialize and checks the allocation): drop this row on a refresh past it. `tools/tree-sitter-sql/src/scanner.c` is this patched file | | swift | `swift/scanner.c`, `OP_SYMBOL_SUPPRESSOR` + `eat_operators` | `1UL <<` / `1 <<` → `1ULL <<` | UBSan: `1 << suppressor` shifts an `int` by up to `TOKEN_COUNT` bits, undefined once the index reaches 31, while the mask it feeds is `uint64_t`. `1UL << FAKE_TRY_BANG` is the same defect on Windows, where `unsigned long` is 32 bits and `FAKE_TRY_BANG` is 32; the CLANGARM64 leg runs UBSan in trap mode, so there it is an illegal instruction rather than a log line. Upstream already carries both changes: `fb63a7004f07` (2026-04-06, upstream #558) for `eat_operators`, `6ab8d1d74ebd` (2026-08-10) for the `OP_SYMBOL_SUPPRESSOR` entry. Our pin `8abb3e8b3325` (2026-03-20) predates both, so this is a backport rather than a local invention — a re-vendor past 2026-08-10 should delete this row, not re-apply it | +| cobol | `cobol/scanner.c`, scan, `LINE_PREFIX_COMMENT` loop and `COMMENT_ENTRY` branch (#2998, #3000) | the column-prefix loop also stops at `lookahead == 0`; `COMMENT_ENTRY` is not emitted when `start_with_word()` consumed nothing | **Livelock at EOF.** `advance()` is a no-op at end of input, so a file reaching EOF at column 5 or less (a `.cob` file shorter than 6 bytes, or the empty line after a final newline in the right parser state) spun the scanner forever and the index worker until its quiet timeout. The `COMMENT_ENTRY` guard is defensive (zero-length external token); with the current tables it cannot fire. In-house grammar (see "Authored in-house"): there is no upstream to re-vendor from, the row records the change for the vendoring audit (`repro_issue2998_*` in `tests/repro/repro_extraction.c`) | ## Vendored from verified upstream diff --git a/scripts/vendored-checksums.txt b/scripts/vendored-checksums.txt index 9993f0d6f..e3d86e1d1 100644 --- a/scripts/vendored-checksums.txt +++ b/scripts/vendored-checksums.txt @@ -5,7 +5,7 @@ c5cfb43042b6b72045f4ba997834d0a7786d2793d91680868b5815b39f14fc78 internal/cbm/v b29c1c9fb7cc82f58c84b376df1297d6e2737a1d655fd356db0859e3c29c2fea internal/cbm/vendored/common/tree_sitter/alloc.h 31e60a1bff6f715afacce03b5b70efe42b58371b4f9595dd4af52a577ff9608c internal/cbm/vendored/common/tree_sitter/array.h 180b893c8734778fd32f372dfbc27bd6ad1cd2221f26150b31256ff6716320d2 internal/cbm/vendored/common/tree_sitter/parser.h -c89ec56087da3b2b0ad8dcad34cd7bb92e10ea7c72ae86f69d9f59daba6cdb3d internal/cbm/vendored/grammars/MANIFEST.md +dc788fdcda5b04821278a7a15fc93b9da49a2e40fb806ef21ad66c49a9117da3 internal/cbm/vendored/grammars/MANIFEST.md ad8425038de519f8c4e3e9339feebf99dfad8a6002dcf79227d91402780a32cc internal/cbm/vendored/grammars/ada/LICENSE 02805ec13939b749c891567be36bf024b09034e04c80683a1ae667272458d549 internal/cbm/vendored/grammars/ada/parser.c 115a75d000bef9c70c4de7dfbb7f2a80b90cbb14ba265056dc7abb1ef3b9b6db internal/cbm/vendored/grammars/ada/tree_sitter/alloc.h @@ -134,7 +134,7 @@ daf550976dc40608917b1f16b5c8b21773111bdd2a7fcc23c5e5fec3737055f5 internal/cbm/v c4b9482069f61a2a26a590181baa34f08eb6dcc57a138def578e6f9720c35ea5 internal/cbm/vendored/grammars/cmake/tree_sitter/parser.h 1f58f9911dc5e3bcb96de28bb28e7b6bb7eb323952d29569c5d7214a152146bb internal/cbm/vendored/grammars/cobol/LICENSE d40a31d4854a2d82977c74d33c3ee9c004d9e63743176ebc84159a1734db7b2b internal/cbm/vendored/grammars/cobol/parser.c -0e146beb0331e4f95e2fb815e263c649f2bc404b35dd1b19eb125cbd4ed95df8 internal/cbm/vendored/grammars/cobol/scanner.c +6958b5867131d6ed02964da9a2a7b5e68db461253c6b122d90c5307055ef3d8c internal/cbm/vendored/grammars/cobol/scanner.c 8e819abdeba5866bf1aaf6e7b97522241c903d94a18395c6a75ed02984270ee8 internal/cbm/vendored/grammars/cobol/tree_sitter/parser.h 00bb7f417416e8233ae465209e72eaa6162d53b061add7d9bed0238552a6fa0c internal/cbm/vendored/grammars/commonlisp/LICENSE 27082ecef6f3fe6c09aaf2488b2003f031a165d23b15179ad6c2b52bf47b05ff internal/cbm/vendored/grammars/commonlisp/parser.c diff --git a/tests/repro/repro_extraction.c b/tests/repro/repro_extraction.c index aa77b7e9a..8afd67ca7 100644 --- a/tests/repro/repro_extraction.c +++ b/tests/repro/repro_extraction.c @@ -14,7 +14,8 @@ #include "cbm.h" #include #if !defined(_WIN32) -#include +#include +#include #include #include #endif @@ -107,46 +108,56 @@ TEST(repro_issue554_cpp_out_of_line_method_class_qualified) { * consuming, another livelock class. * * Expected: extraction RETURNS (the hang itself is the failure mode; the - * fork+deadline harness below turns a regression back into a RED test instead - * of a hung CI job), and the canonical valid-program fixture still extracts - * PROGRAM-ID. Actual (buggy): never returns; last worker-log line + * fork + CPU-time-cap harness below turns a regression back into a RED test + * instead of a hung CI job), and the canonical valid-program fixture still + * extracts PROGRAM-ID. Actual (buggy): never returns; last worker-log line * "pass.start pass=definitions". * ─────────────────────────────────────────────────────────────────── */ #if !defined(_WIN32) -/* Parse src in a forked child under a wall-clock deadline. - * Returns the child's exit code (0 = extraction returned), -1 on timeout - * (child killed; i.e. the livelock reproduced), -2 on fork failure. */ -static int repro2998_parse_with_deadline(const char *src, CBMLanguage lang, const char *path) { +/* CPU seconds the child may spend. Parsing these few bytes costs microseconds + * even under sanitizers; the livelock spends CPU without bound. */ +enum { REPRO2998_CPU_SECONDS = 5 }; + +/* Parse src in a forked child whose CPU time is capped (RLIMIT_CPU), and wait + * for it with one blocking waitpid. A livelock burns CPU and is stopped by + * SIGXCPU; a busy host only delays the child without spending its CPU time, so + * the verdict does not depend on wall-clock time and nothing polls or sleeps. + * Returns the child's exit code (0 = extraction returned), 128 + the signal + * that stopped it (SIGXCPU/SIGKILL = the livelock reproduced), -2 on fork + * failure, -3 if the child could not be waited for. */ +static int repro2998_parse_cpu_capped(const char *src, CBMLanguage lang, const char *path) { fflush(NULL); pid_t pid = fork(); if (pid < 0) return -2; if (pid == 0) { + struct rlimit no_core = {0, 0}; + struct rlimit cpu = {REPRO2998_CPU_SECONDS, REPRO2998_CPU_SECONDS + 1}; + (void)setrlimit(RLIMIT_CORE, &no_core); + (void)setrlimit(RLIMIT_CPU, &cpu); CBMFileResult *r = cbm_extract_file(src, (int)strlen(src), lang, "t", path, 0, NULL, NULL); if (r) cbm_free_result(r); _exit(0); /* reaching _exit at all is what the bug took away */ } int status = 0; - for (int i = 0; i < 1000; i++) { /* 10 s in 10 ms steps */ - pid_t got = waitpid(pid, &status, WNOHANG); - if (got == pid) - return WIFEXITED(status) ? WEXITSTATUS(status) : 128 + WTERMSIG(status); - usleep(10 * 1000); - } - kill(pid, SIGKILL); - waitpid(pid, &status, 0); - return -1; + pid_t got; + do { + got = waitpid(pid, &status, 0); + } while (got < 0 && errno == EINTR); + if (got != pid) + return -3; + return WIFEXITED(status) ? WEXITSTATUS(status) : 128 + WTERMSIG(status); } TEST(repro_issue2998_cobol_scanner_eof_livelock) { /* EOF lands inside the LINE_PREFIX_COMMENT column scan: shorter than * column 6, or a trailing newline leaving the lexer at column 0 of the * virtual empty last line. */ - ASSERT_EQ(repro2998_parse_with_deadline("X", CBM_LANG_COBOL, "m.cob"), 0); - ASSERT_EQ(repro2998_parse_with_deadline("*<<", CBM_LANG_COBOL, "m.cob"), 0); - ASSERT_EQ(repro2998_parse_with_deadline("X\n", CBM_LANG_COBOL, "m.cob"), 0); - ASSERT_EQ(repro2998_parse_with_deadline("display 1.\n", CBM_LANG_COBOL, "m.cob"), 0); + ASSERT_EQ(repro2998_parse_cpu_capped("X", CBM_LANG_COBOL, "m.cob"), 0); + ASSERT_EQ(repro2998_parse_cpu_capped("*<<", CBM_LANG_COBOL, "m.cob"), 0); + ASSERT_EQ(repro2998_parse_cpu_capped("X\n", CBM_LANG_COBOL, "m.cob"), 0); + ASSERT_EQ(repro2998_parse_cpu_capped("display 1.\n", CBM_LANG_COBOL, "m.cob"), 0); PASS(); }