Skip to content

fix(core): Call native toString without page-replaceable lookups in FunctionToString - #25921

Merged
logaretm merged 1 commit into
developfrom
awad/function-to-string-bound-native-call
Oct 30, 2026
Merged

logaretm merged 1 commit into
developfrom
awad/function-to-string-bound-native-call

Conversation

@logaretm

@logaretm logaretm commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

FunctionToString could overflow the stack, it happens when a page hooks Function.prototype.apply or when toString gets a huge argument list, this can be fixed by capturing a binding to the native call once and passing no arguments.

Why does a huge argument list trigger this? V8 only fits so many args on the stack. Our wrapper held two copies (the incoming call and our call to native toString), so a huge list overflows where native's single copy fits. This is mentioned on MDN.

I added tests for an apply hook that calls toString and a 100k argument call, both overflow before the fix.

Related to #22515, which removed the same kind of re-entry through Reflect.apply.


⚠️ This is a guess at best at an issue that was reported, no guarantee it fixes it because it seems far fetched that this is what happened. Feel free to close if this is too much.

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Compared: 278c7e9 (PR test merge using develop at 7aca628)

Against: 7aca628 (develop) · base run #64423

✅ Baseline matches: this diff contains only this PR's changes.

Path Size % Change Change
@sentry/browser 30.39 kB +0.01% +3 B 🔺
@sentry/browser - with treeshaking flags 28.54 kB +0.02% +3 B 🔺
@sentry/browser - with treeshaking flags tracing without tracing 28.42 kB +0.01% +2 B 🔺
@sentry/browser (incl. Tracing) 52.71 kB +0.02% +6 B 🔺
@sentry/browser (incl. Tracing + Span Streaming) 52.72 kB +0.02% +6 B 🔺
@sentry/browser (incl. Tracing, Profiling) 55.69 kB +0.01% +4 B 🔺
@sentry/browser (incl. Tracing, Replay) 93.01 kB +0.01% +5 B 🔺
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 81.61 kB +0.01% +6 B 🔺
@sentry/browser (incl. Tracing, Replay with Canvas) 97.76 kB +0.01% +6 B 🔺
@sentry/browser (incl. Tracing, Replay, Feedback) 110.75 kB +0.01% +2 B 🔺
@sentry/browser (incl. Feedback) 47.98 kB +0.02% +5 B 🔺
@sentry/browser (incl. sendFeedback) 35.5 kB +0.01% +3 B 🔺
@sentry/browser (incl. FeedbackAsync) 40.6 kB +0.01% +2 B 🔺
@sentry/browser (incl. Metrics) 31.43 kB +0.03% +8 B 🔺
@sentry/browser (incl. Logs) 31.72 kB +0.02% +4 B 🔺
@sentry/browser (incl. Metrics & Logs) 32.44 kB +0.03% +7 B 🔺
@sentry/react 32.28 kB +0.02% +6 B 🔺
@sentry/react (incl. Tracing) 55.08 kB +0.02% +8 B 🔺
@sentry/vue 38.66 kB +0.01% +2 B 🔺
@sentry/vue (incl. Tracing) 55.73 kB +0.01% +5 B 🔺
@sentry/svelte 30.42 kB +0.01% +3 B 🔺
@sentry/remix (Remix 3 client bundle) 57.79 kB +0.02% +6 B 🔺
CDN Bundle 32.18 kB +0.03% +7 B 🔺
CDN Bundle (incl. Tracing) 53.23 kB +0.02% +6 B 🔺
CDN Bundle (incl. Logs, Metrics) 34.46 kB +0.03% +8 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 55.17 kB +0.01% +2 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 75.87 kB +0.01% +6 B 🔺
CDN Bundle (incl. Tracing, Replay) 91.45 kB +0.01% +9 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 93.38 kB +0.01% +2 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 97.55 kB -0.01% -2 B 🔽
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 99.55 kB +0.01% +7 B 🔺
CDN Bundle - uncompressed 94.64 kB +0.03% +22 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 157.6 kB +0.02% +22 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 101.11 kB +0.03% +22 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 163.34 kB +0.02% +22 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 232.68 kB +0.01% +22 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 279.29 kB +0.01% +22 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 285.01 kB +0.01% +22 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 293 kB +0.01% +22 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 298.71 kB +0.01% +22 B 🔺
@sentry/nextjs (client) 57.88 kB +0.02% +7 B 🔺
@sentry/sveltekit (client) 53.23 kB +0.02% +8 B 🔺
@sentry/core/server 44.24 kB - -
@sentry/core/browser 13.93 kB - -
@sentry/node 154.95 kB +0.02% +19 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 82.08 kB - -
@sentry/node - without tracing 96.23 kB +0.03% +24 B 🔺
@sentry/node - without channel injection 135.34 kB +0.02% +22 B 🔺
@sentry/aws-serverless 104.42 kB +0.04% +32 B 🔺
@sentry/cloudflare (withSentry) - minified 197.94 kB +0.02% +22 B 🔺
@sentry/cloudflare (withSentry) 491.97 kB +0.02% +84 B 🔺
@sentry/nextjs/cloudflare (withSentry) - minified 218.36 kB +0.02% +22 B 🔺

View base workflow run

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Optional E2E tests

Some optional checks were not successful. They do not block the merge. 4 not successful, 50 successful. See the run.

Check Status
❌ CI: Optional E2E Tests / E2E cloudflare-workers-send-to-sentry Test (optional) Failing after 4m Details
❌ CI: Optional E2E Tests / E2E cloudflare-flue-send-to-sentry Test (optional) Failing after 3m Details
❌ CI: Optional E2E Tests / E2E gen-ai-libraries (latest) Test (optional) Failing after 41s Details
❌ CI: Optional E2E Tests / E2E nuxt-5 Test (optional) Failing after 2m Details
Successful checks
Check Status
✅ CI: Optional E2E Tests / E2E cloudflare-agent Test (optional) Successful in 57s Details
✅ CI: Optional E2E Tests / E2E cloudflare-pi-durable (latest) Test (optional) Successful in 27s Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries (cloudflare) Test (optional) Successful in 33s Details
✅ CI: Optional E2E Tests / E2E nestjs-12 (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-pi-durable Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E astro-7-static Test (optional) Successful in 46s Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (deno) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (cloudflare, latest) Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E astro-7 Test (optional) Successful in 54s Details
✅ CI: Optional E2E Tests / E2E debug-id-sourcemaps Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E deno (latest) Test (optional) Successful in 45s Details
✅ CI: Optional E2E Tests / E2E cloudflare-think Test (optional) Successful in 36s Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps Test (optional) Successful in 21s Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (static / nuxt generate) Test (optional) Successful in 21s Details
✅ CI: Optional E2E Tests / E2E cloudflare-think (ai v6) Test (optional) Successful in 40s Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-eve (latest) Test (optional) Successful in 42s Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext, bun) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries Test (optional) Successful in 46s Details
✅ CI: Optional E2E Tests / E2E node-eve (orchestrion) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-eve Test (optional) Successful in 46s Details
✅ CI: Optional E2E Tests / E2E nextjs-16-tunnel (cloudflare) Test (optional) Successful in 45s Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions Test (optional) Successful in 16s Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-cloudflare Test (optional) Successful in 22s Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v1 Test (optional) Successful in 15s Details
✅ CI: Optional E2E Tests / E2E nextjs-14 (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-flue (latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E react-router-7-framework-instrumentation Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 (tracer provider) Test (optional) Successful in 21s Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry-static Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (turbo) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-flue Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E react-send-to-sentry Test (optional) Successful in 5m Details
✅ CI: Optional E2E Tests / E2E cloudflare-mastra Test (optional) Successful in 26s Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v2 Test (optional) Successful in 17s Details
✅ CI: Optional E2E Tests / E2E nextjs-orpc Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-mastra Test (optional) Successful in 45s Details
✅ CI: Optional E2E Tests / E2E node-mastra (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-pi-durable (latest) Test (optional) Successful in 27s Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 Test (optional) Successful in 23s Details
✅ CI: Optional E2E Tests / E2E node-pi-durable Test (optional) Successful in 22s Details
✅ CI: Optional E2E Tests / E2E supabase-nextjs Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (client source maps kept) Test (optional) Successful in 22s Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions (latest) Test (optional) Successful in 17s Details
✅ CI: Optional E2E Tests / E2E solidstart-2 Test (optional) Successful in 35s Details
✅ CI: Optional E2E Tests / E2E vue-3 (no Options API) Test (optional) Successful in 52s Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps Test (optional) Successful in 21s Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react (latest) Test (optional) Successful in 1m Details

@logaretm

Copy link
Copy Markdown
Member Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 9ab72e4. Configure here.

logaretm added a commit that referenced this pull request Oct 30, 2026
…in FunctionToString (#25922)

Backport of: #25921

---

`FunctionToString` could overflow the stack, it happens when a page
hooks `Function.prototype.apply` or when `toString` gets a huge argument
list, this can be fixed by capturing a binding to the native call once
and passing no arguments.

**Why does a huge argument list trigger this?** V8 only fits so many
args on the stack. Our wrapper held two copies (the incoming call and
our call to native `toString`), so a huge list overflows where native's
single copy fits. This is mentioned on
[MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply#:~:text=But%20beware%3A%20by%20using%20apply()%20(or%20the%20spread%20syntax)%20with%20an%20arbitrarily%20long%20arguments%20list%2C%20you%20run%20the%20risk%20of%20exceeding%20the%20JavaScript%20engine%27s%20argument%20length%20limit.).

I added tests for an apply hook that calls toString and a 100k argument
call, both overflow before the fix.

Related to #22515, which removed the same kind of re-entry through
`Reflect.apply`. This is a guess at best at an issue that was reported,
no guarantee it fixes it because it seems far fetched that this is what
happened.
…unctionToString

Bind the native toString once at setup instead of calling it through
Function.prototype.apply, which a page can replace, and stop forwarding
arguments native toString ignores. Either could overflow the stack where
the native method would not.
@logaretm
logaretm force-pushed the awad/function-to-string-bound-native-call branch from 9ab72e4 to c176ec0 Compare October 30, 2026 14:14
@logaretm
logaretm marked this pull request as ready for review October 30, 2026 14:55
@logaretm
logaretm requested review from a team as code owners October 30, 2026 14:55
@logaretm
logaretm requested review from Lms24 and msonnb and removed request for a team October 30, 2026 14:55
@logaretm
logaretm merged commit 299a3c3 into develop Oct 30, 2026
391 of 395 checks passed
@logaretm
logaretm requested review from andreiborza and isaacs and removed request for a team October 30, 2026 14:55
@logaretm
logaretm deleted the awad/function-to-string-bound-native-call branch October 30, 2026 14:55
@logaretm
logaretm requested review from chargome and nicohrubec and removed request for a team October 30, 2026 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants