Skip to content

fix(javascript): handle oversized inline source maps - #1386

Merged
N0zoM1z0 merged 2 commits into
morluto:mainfrom
cold-atom:fix/issue-1380
Oct 10, 2026
Merged

N0zoM1z0 merged 2 commits into
morluto:mainfrom
cold-atom:fix/issue-1380

Conversation

@cold-atom

@cold-atom cold-atom commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

A large inline source-map directive in a two-byte JavaScript source can overflow V8's regexp stack before application analysis finishes. Read the directive with fixed-prefix checks and single-character-class searches, preserving complete declared URLs and source ranges. This also handles long whitespace before the name, equals sign, and URL.

Fixes #1380.

Validation of final head b117b121:

  • npm run test:focused -- src/domain/javascript/javascriptStaticAnalysisSourceMaps.test.ts: 34 passed.
  • Real public CLI, Node 24.18.0 and Node 22.22.2: the same 38.1 MB source-owned application fails on main 7aa4d768 and succeeds here; its 9,600,223-character inline URL and three 9.5M-space directive variants retain exact URLs.
  • Real stdio MCP, Node 24.18.0: analysis completes, reports the existing transport resource constraint, and exports the complete retained Evidence in the same session. This verifies recovery, not that the result fits the default receive budget.
  • Final-head CI and real JavaScript recovery both pass.

No Hopper/Ghidra verification was needed for this JavaScript parser change.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@CassieFox23

CassieFox23 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: This fixes the crash from the issue. One hostile input still crashes the whole run.

What passes

  • The source map test file passes. That is 21 of 21 on both Nodes.
  • Your 9M map case passes.
  • A 12M map in a two-byte file passes.
  • Trailing whitespace after the URL passes.
  • The /*# ... */ form and the //@ form pass.
  • I built a two-byte app with a 9.6M map. End to end, it now works.
  • That app exits 0 here. Release 6.3.0 exits 1 on it.

What still fails

A long run of spaces in a \s* slot still overflows. I passed this whole to analyzeJavaScriptStaticSource:

'ğ//# sourceMappingURL=' + ' '.repeat(9_500_000) + 'x'

It throws RangeError: Maximum call stack size exceeded. Both Nodes fail the same way. The throw comes from the prefix regex exec. I first showed this in my comment on #1380.

End to end, it kills the whole run. The CLI returns execution_failure and exits 1. It is not caught per file. Real bundles won't look like this. A hostile file could.

Not run

  • The full test suite.
  • CI. None had run when I checked.
  • Node 26, macOS or Windows.

Thanks, cold-atom, for the quick fix!

A possible shape

Drop the regex for the prefix. Match the fixed text with startsWith. Find each boundary with a one-class search:

const skip = c.slice(i).search(/\S/u);
if (skip === -1) continue;
i += skip;
if (!c.startsWith("sourceMappingURL", i)) continue;
const end = c.slice(i).search(/[\s*]/u);

I tried this shape locally. It handled 9.5M spaces in each of the three slots. It passed on both Nodes.

Test setup
  • Box: Linux
  • Node: 22.23.1, 24.18.0
  • Head: 3a28bc0e

🤖 Generated with Claude Code (Opus 5.5) 🦊

@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: On Node 26 this PR passes every case. That includes the hostile one. That one still fails on 22 and 24.

Earlier I said Node 26 was not run. Here it is. I used head 3a28bc0e and Node 26.11.1.

check 22.23.1 24.18.0 26.11.1
source map tests 21/21 21/21 21/21
big maps, all comment forms pass pass pass
9.5M spaces after = throws throws pass
two-byte app, big map exit 0 exit 0 exit 0
same app, 9.5M spaces exit 1 exit 1 exit 0

So Node 26 handles the long \s* run. The engines field still lists 22 and 24. The gap stays open there.

🤖 Generated with Claude Code (Opus 5.5) 🦊

@cold-atom

Copy link
Copy Markdown
Contributor Author

Thanks for the additional testing. I pushed commit b117b12, which replaces the unbounded source-map prefix regex with fixed-text checks and bounded searches. It also adds regression coverage for the 9.5M-space cases. The earlier results were against 3a28bc0; please retest the latest PR head when the checks are available.

@N0zoM1z0 N0zoM1z0 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed final head b117b12. Fixed-prefix checks plus single-class searches cover both the oversized URL and long whitespace cases without regexp backtracking. The 34 focused tests pass; the same real application fails on main and succeeds via public CLI on Node 22/24. Real stdio MCP preserves the transport diagnostic and exports complete retained Evidence successfully. All final-head checks are green. Large result delivery remains a separate follow-up.

@N0zoM1z0
N0zoM1z0 merged commit 5fc4d79 into morluto:main Oct 10, 2026
20 checks passed
@CassieFox23

CassieFox23 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: The new commit fixes the last crash. Every case I had now passes on Node 22, 24 and 26.

check 22 24 26
source map tests 34/34 34/34 34/34
9.5M spaces after the marker pass pass pass
9.5M spaces before = pass pass pass
9.5M spaces after = pass pass pass
big maps, all three comment forms pass pass pass
app with 9.5M spaces, end to end exit 0 exit 0 exit 0

The 34 tests are the 21 old ones plus your 13 new ones.

The hostile app used to exit 1 on 22 and 24. Now it exits 0. The output holds the full 9.6M map URL.

I also tried a few extra shapes. Spaces in all three slots at once pass. So do the //@ and /*# */ forms with long spaces. A run of spaces with no URL finds nothing, as it should. Runs near 2^23 spaces pass too.

Your new tests do catch the old bug. I ran them against 3a28bc0e on Node 22. The three 9.5M space tests fail there. The rest pass.

I also looked for slow inputs. The new searches each scan once, so they stay linear. I built a 5.5 MB file with 200k near-miss lines. It took under 0.2 seconds on each Node. A 3.3 MB file with 10k real directives is slow. It took 33 to 40 seconds here. Release 6.3.0 is slow on it too. The time goes to older code, not your change.

Not run

  • The full test suite. I ran the source map file and three related files. Edit: done. It passed on all three Nodes. The results are in my follow-up comment.
  • macOS or Windows. I only tested Linux.
  • I did not run CI myself. The PR page shows all 20 checks passing on b117b121.

Thanks, cold-atom, for the quick turnaround!

Test setup
  • Box: Linux
  • Node: 22.23.1, 24.18.0, 26.11.1
  • Head: b117b121

🤖 Generated with Claude Code (Opus 5.5) 🦊

@CassieFox23

CassieFox23 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR: I ran the full test suite on this PR. It passes on Node 22, 24 and 26. Nothing failed.

My last note listed the full suite as not run. Here it is.

check 22 24 26
tests passed 6283 6283 6283
tests failed 0 0 0
tests skipped 89 89 89
test files 687 + 11 skipped 687 + 11 skipped 687 + 11 skipped
type check - pass -
oxlint - pass -
format check - pass -

The skips come from macOS, Windows and host checks in the tests. Linux skips them by design. oxlint shows warnings but no errors. None are in the two files this PR changes. The lint script then runs a boundary check, which needs git.

Not run

  • macOS or Windows.
  • The module boundary and test discovery checks. They need a git checkout. I tested a plain export.
  • The rest of the CI static checks, such as knip and jscpd.
  • Coverage. I ran the tests without it.

Thanks again, cold-atom!

Commands
npm ci
npm run compile
node scripts/generate-mcp-tool-catalog.mjs
node scripts/generate-skill-metadata.mjs
node scripts/generate-product-catalog.mjs
node scripts/generate-completion-ledger.mjs
npm run typecheck
npm run lint
npm run format:check
node node_modules/vitest/vitest.mjs run
Test setup

🤖 Generated with Claude Code (Opus 5.5) 🦊

darsrc pushed a commit to darsrc/rea that referenced this pull request Oct 10, 2026
* fix(javascript): handle oversized inline source maps

* fix(javascript): avoid source map directive regex overflow
@morluto morluto added bug Something isn't working area: domain Domain logic, errors, and pure functions labels Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: domain Domain logic, errors, and pure functions bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] analyze-javascript-application aborts with RangeError on a large inline source map in a two-byte source

4 participants