← Back to Pull requests

deps: V8: backport 786c1c2d88d4 #66249

Closed
unknown closed this pull request without merging on Sep 26, 2026 16:27 UTC
View on GitHub
unknown unknown commented on Sep 23, 2026 20:32 UTC
Author

Fixes: https://github.com/nodejs/node/issues/66074

This floats the upstream V8 fix 786c1c2d88 (CL 8426465, "[stack-traces] Fix overflow in Error.stackTraceLimit trimming"). I wrote that CL. As requested in the issue, this targets main first.

The bug

The regression comes from #65764 (deps: V8: backport ebd15783b7ba). When stack traces are captured for uncaught exceptions (--trace-uncaught, or an attached inspector), Isolate::CaptureAndSetErrorStack trims the raw call-site data with stack_trace_limit CallSiteInfo::Fields::kCount. In our V8 14.6 tree kCount is 6 and the arithmetic is signed int, so large limits overflow. Infinity is clamped to INT_MAX, and INT_MAX 6 wraps to -6. That fails CHECK_GT(new_capacity, 0) in RightTrim:

$ node --trace-uncaught -e 'Error.stackTraceLimit=Infinity; Error()'
#
# Fatal error in , line 0
# Check failed: new_capacity > 0.

It reproduces on v27.0.0-nightly202609233d85c94cfa (linux-x64). It does not reproduce on v27.0.0-nightly2026090729667e046b, which was built before #65764 landed.

Measured with an Error about 59 frames deep under --trace-uncaught, before the fix:

| Error.stackTraceLimit | Result |
|---|---|
| 0 … 357913941 | correct |
| 357913942 … 715827882 | crash |
| 715827883 … 715827941 | silently loses frames (0 … 58 of 59) |
| 715827942 … 1073741823 | correct |
| 1073741824 … 1431655765 | crash |
| 1431655766 … 1431655824 | silently loses frames |
| 1431655825 … 1789569706 | correct |
| ≥ 1789569707, including 1e10 and Infinity | crash |

In general, a limit crashes when int32(limit 6) is negative, and it silently truncates when the result falls in [0, raw length). The frame-loss windows are as wide as the captured stack. Without --trace-uncaught / inspector, nothing goes wrong.

The fix

Compare the limit against the number of frames (ulength() / kCount) and multiply only after the limit is known to be smaller. The upstream commit didn't apply cleanly to 14.6 because V8 main's ulength() returns a wrapper (.value()), while 14.6 returns a plain uint32_t. The resolved hunk is identical to upstream except that .value() is dropped. v8_embedder_string is bumped to -node.35.

The CL's cctest (CaptureStackTraceForUncaughtExceptionHugeStackTraceLimit) is included in the backport. With kCount == 6, its Infinity case is the one that exercises the bug in this tree.

Interaction with the V8 15.2 update (#65161)

  • 786c1c2d88 landed at main@{#110043}, during V8 15.6 development. The 15.2 through 15.5 branches were cut before it, and none of them has a merge-back. So #65161 (V8 15.2.124.34) does not contain the fix. Its isolate.cc still has the unfixed multiplication. There the symptom would change from a crash to silent frame loss, starting at 858993460.

  • The upstream commit applies cleanly (line offsets only) to deps/v8 in #65161. After 15.2 it can be a plain deps: V8: cherry-pick 786c1c2d88d4, and it would be good to include that in #65161. If this PR lands first, the patch would be refloated on top of the 15.2 update, where it applies cleanly.

  • The commit in this PR cherry-picks cleanly onto v26.x-staging, which has the same isolate.cc and embedder string -node.34.
  • Testing

    On linux-x64 with a local release build of this branch:

  • Repro and limits: the issue's repro and all the limits above now yield the full stack with no crash, including every boundary value, 232, 1e10 and Infinity. Small limits still trim: 0 → 0 frames, 1 → 1, 10 → 10.

  • Full suite: ran make -j8 test-only:

  • - C++ cctest: 264/264 passed.
    - JS tests: 7382 passed, 1 failed.
    - make tooltest: 15/15 passed.
  • The one failure is parallel/test-fs-rmSync-special-char-additional-error (ENOENT … chmod '…/速_dir'). It is not related to this change: it fails the same way on the unpatched nightlies v27.0.0-nightly2026090729667e046b and v27.0.0-nightly202609233d85c94cfa on the same machine, which runs tests as root.

  • Not run: make test-v8.
  • CI

    Please start both a regular Node.js CI run and a V8 CI* run (node-test-commit-v8-linux). Only V8 CI builds and runs the added V8 cctest.

    AI assistance

    Parts of this work were done with a closed-source coding agent, as disclosed by the Assisted-by trailer on the commit. I wrote the original V8 CL. I reviewed the full diff and the resolved isolate.cc hunk myself, and verified the reproduction, the boundary values and the test results on this machine.

    /cc @silverwind (reporter) @richardlau (asked for the float) @nodejs/v8-update

    Diff: 603 lines (+452 / -151) across 7 files Reviewer: aduh95 Review duration: 4075m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 603 lines diff across 7 files
    0.50
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.383
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #66249"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 50.1% (MEDIUM) · Higher = larger blast radius
    50.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.8% · Safe to merge
    19.8%
    Repository