René's URL Explorer Experiment


Title: fix(core): iOS double free of V8-owned buffers; getRandomValues view handling by edusperoni · Pull Request #11370 · NativeScript/NativeScript · GitHub

Open Graph Title: fix(core): iOS double free of V8-owned buffers; getRandomValues view handling by edusperoni · Pull Request #11370 · NativeScript/NativeScript

X Title: fix(core): iOS double free of V8-owned buffers; getRandomValues view handling by edusperoni · Pull Request #11370 · NativeScript/NativeScript

Description: PR Checklist The PR title follows our guidelines: https://github.com/NativeScript/NativeScript/blob/master/tools/notes/CONTRIBUTING.md#commit-messages. There is an issue for the bug/feature this PR is for. To avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it. You have signed the CLA. All existing tests are passing: https://github.com/NativeScript/NativeScript/blob/master/tools/notes/DevelopmentWorkflow.md#running-unit-tests-application. Tests for the changes are included - https://github.com/NativeScript/NativeScript/blob/master/tools/notes/WritingUnitTests.md. What is the current behavior? 1 & 2 — V8-owned buffers donated to Foundation (iOS) Two iOS call sites hand a V8-owned pointer to dataWithBytesNoCopy:length:. The 2-arg selector is freeWhenDone:YES — Foundation takes ownership of the pointer and frees it. The same allocation is freed a second time by V8's ArrayBufferSweeper when the ArrayBuffer dies. Because the second free is deferred, it lands on whatever recycled small-heap chunk occupies that address by then, so the victim — and therefore the symptom — rotates with allocation layout. In a production app this surfaced as V8_Fatal in the runtime's kFinalizer machinery, plus rotating SIGSEGV flavours (corrupted wrappers, zeroed Persistent slots, payload-overwritten vptrs) on worker threads ~30–70s into a session; some runs hung silently instead. malloc_history on a parked process captured both stacks verbatim on a single chunk: the Foundation-side free under -[NSConcreteMutableData initWithBytes:length:copy:deallocator:], and later ArrayBufferSweeper::SweepingJob → shared_ptr::__on_zero_shared → ~BackingStore → free. 1. Crypto.getRandomValues — packages/core/wgc/crypto/index.ts (the production trigger) const data = NSMutableData.dataWithBytesNoCopyLength(typedArray, typedArray.byteLength); NSCCrypto.getRandomValues(data); The donated pointer is the caller's typed array's V8 BackingStore buffer. For small payloads NSConcreteMutableData copies and free()s the donor immediately inside initWithBytes:length:copy:deallocator:; larger payloads free at dealloc. Either way Foundation frees memory V8 owns. Every crypto.getRandomValues() call is one occurrence, and it backs UUID generation, so it fires constantly on UI paths. Since wgc (and global.crypto) is new in core 9.x, apps upgrading from 8.x hit this the moment anything calls crypto.getRandomValues / crypto.randomUUID. 2. FileSystemAccess.getBuffer — packages/core/file-system/file-system-access.ios.ts (write path) const buf = NSData.dataWithData(buffer?.buffer); const len = buffer.byteLength; return NSData.dataWithBytesNoCopyLength(buf.bytes.add(buffer?.byteOffset ?? 0), len); Same freeWhenDone:YES, but over an interior pointer of another NSData's buffer: free() on a non-chunk-start pointer whenever byteOffset > 0 — immediate heap corruption; a double free against buf's own dealloc even at offset 0. It also copies the entire underlying ArrayBuffer (dataWithData(buffer.buffer)) even when the view is a small window over it. 3 — getRandomValues overwrites past the caller's window (Android) typedArray = new Uint8Array(typedArray.buffer, typedArray.byteOffset); No length, so the reinterpreted view runs from the caller's offset to the end of the ArrayBuffer. The runtime maps a typed array to a direct ByteBuffer over backingStore->Data() + array->ByteOffset() with capacity array->ByteLength(), and Crypto.java fills the whole capacity after a rewind(): buffer.rewind(); int size = buffer.capacity(); byte[] tempBuf = new byte[size]; random.nextBytes(tempBuf); buffer.put(tempBuf); So for any non-byte typed array that is a window over a larger buffer, every byte from the view's offset to the end of that buffer is overwritten with randomness. new Uint32Array(buffer32, 8, 2) asks for 8 bytes and gets 24 clobbered. 4 — getRandomValues returns an object the caller never passed in Both branches assign the coerced view over the typedArray parameter and then return typedArray, so for any non-byte typed array the caller gets back a Uint8Array rather than its own view. WebCrypto requires the same object back. #10658 added the missing return, but by then the parameter had already been reassigned. The randomness does land correctly (the buffer is shared), so this is a return-value defect only. What is the new behavior? 1. The 3-arg freeWhenDone:NO form: const data = NSMutableData.dataWithBytesNoCopyLengthFreeWhenDone(bytes, bytes.byteLength, false); Zero-copy behaviour is preserved — native randomness is still written directly into the JS buffer — with no ownership donation. The buffer is guaranteed alive for the duration of the synchronous call. 2. The whole else branch collapses to a single copying call: return NSData.dataWithBytesLength(buffer, buffer.byteLength); Passing the typed-array view itself as the const void *bytes parameter: the iOS runtime's pointer marshalling resolves it to backingStore->Data() + byteOffset (view-aware — audited against the runtime source), and dataWithBytes:length: copies exactly the view's window. Net result — one copy of only the window instead of a full-buffer copy plus an unsafe no-copy wrapper, no intermediate NSData, no ownership games. 3 & 4. The coercion is now a local bound to the caller's window, and the parameter is returned untouched: getRandomValues>(typedArray: T): T { const bytes = typedArray.BYTES_PER_ELEMENT === 1 ? typedArray : new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength); ... return typedArray; } The generic signature preserves the caller's element type, matching the DOM's getRandomValues(array: T): T. Validation With the two iOS ownership changes patched into core (unmodified runtime), a previously 100%-reproducible ~60s crash survived 10+ minute soaks including document close/reopen cycles — on both a fixed runtime and the original unfixed runtime, making bug 1 the proven sole production trigger. Tests New specs pin the selector and arguments each path picks, since ownership of the bytes is exactly what the selector choice decides, plus the window and identity guarantees: packages/core/wgc/crypto/index.spec.ts — iOS: freeWhenDone is false, the view itself is passed, and only the view's window is wrapped. Android: a byte view passes straight through, and a non-byte typed array is reinterpreted over its window only. Both: the object handed in is the object handed back. packages/core/file-system/file-system-access.ios.spec.ts — ArrayBuffer still copies whole; Uint8Array, offset Uint8Array, offset Uint8ClampedArray and offset DataView all pass the view itself to dataWithBytes:length: with the window's byteLength. packages/core/vitest.setup.ts gains NSData / NSMutableData / NSCCrypto stubs that record the selector and arguments they were called with, plus the Android org.nativescript.winter_tc.Crypto shim so both platform branches are reachable from the specs. 10 of the 13 new assertions fail against main and pass here; the other 3 cover behaviour this PR deliberately leaves alone. The full core suite passes (442 tests), and lint/build are clean. Sweep Any 2-arg dataWithBytesNoCopy:length: (or the NSMutableData equivalent) over a pointer derived from a typed array, interop.handleof, or another NSData's bytes is this bug class. A repo-wide sweep found no other reachable JS-side occurrences. The one remaining native hit — [NSData dataWithBytesNoCopy:exponent length:size] in packages/winter-tc/ios/NSCWinterTC/NSCWinterTC/NSCCrypto.m (generateKeyRsa) — is currently unreachable: every core call site passes null, 0 for the exponent (// ignore publicExponent for now). Worth tightening whenever that path is implemented. Cross-reference The iOS runtime side is tracking a debug-build marshalling guard (warn when the 2-arg selector receives a pointer inside a live V8 BackingStore); NativeScript/ios#458 carries the full forensic narrative.

Open Graph Description: PR Checklist The PR title follows our guidelines: https://github.com/NativeScript/NativeScript/blob/master/tools/notes/CONTRIBUTING.md#commit-messages. There is an issue for the bug/feature this...

X Description: PR Checklist The PR title follows our guidelines: https://github.com/NativeScript/NativeScript/blob/master/tools/notes/CONTRIBUTING.md#commit-messages. There is an issue for the bug/feature this...

Opengraph URL: https://github.com/NativeScript/NativeScript/pull/11370

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:3663cf3f-6e2f-b0bd-7989-f204a693f8db
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idB13C:2AAD2E:15F52CB:1D4BA66:6B013C69
html-safe-noncef5b69ce33d9a913ebf46c38edd17bbf7a9e33cfce6f1db2a1b58faca3016f3bb
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMTNDOjJBQUQyRToxNUY1MkNCOjFENEJBNjY6NkIwMTNDNjkiLCJ2aXNpdG9yX2lkIjoiNTUyNTg1NjcwOTUyNTk3ODIxNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacdd12f4b3f819a6f67a03143cc88c91b48e0949cb169eb65263a908dd61734dfa
hovercard-subject-tagpull_request:4377230391
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/NativeScript/NativeScript/pull/11370/files
twitter:imagehttps://avatars.githubusercontent.com/u/4061767?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/4061767?s=400&v=4
og:image:altPR Checklist The PR title follows our guidelines: https://github.com/NativeScript/NativeScript/blob/master/tools/notes/CONTRIBUTING.md#commit-messages. There is an issue for the bug/feature this...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/NativeScript/NativeScript git https://github.com/NativeScript/NativeScript.git
octolytics-dimension-user_id7392261
octolytics-dimension-user_loginNativeScript
octolytics-dimension-repository_id31492490
octolytics-dimension-repository_nwoNativeScript/NativeScript
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id31492490
octolytics-dimension-repository_network_root_nwoNativeScript/NativeScript
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/NativeScript/NativeScript/pull/11370/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FNativeScript%2FNativeScript%2Fpull%2F11370%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FNativeScript%2FNativeScript%2Fpull%2F11370%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=NativeScript%2FNativeScript
Reloadhttps://github.com/NativeScript/NativeScript/pull/11370/files
Reloadhttps://github.com/NativeScript/NativeScript/pull/11370/files
Reloadhttps://github.com/NativeScript/NativeScript/pull/11370/files
NativeScripthttps://github.com/NativeScript
NativeScripthttps://github.com/NativeScript/NativeScript
Codehttps://github.com/NativeScript/NativeScript
Issues231 (231)https://github.com/NativeScript/NativeScript/issues
Pull requests107 (107)https://github.com/NativeScript/NativeScript/pulls
Discussionshttps://github.com/NativeScript/NativeScript/discussions
Actionshttps://github.com/NativeScript/NativeScript/actions
Projectshttps://github.com/NativeScript/NativeScript/projects
Wikihttps://github.com/NativeScript/NativeScript/wiki
Security and qualityhttps://github.com/NativeScript/NativeScript/security
Insightshttps://github.com/NativeScript/NativeScript/insights
Sign up for GitHub https://github.com/signup?return_to=%2FNativeScript%2FNativeScript%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2FNativeScript%2FNativeScript%2Fissues%2Fnew%2Fchoose
NathanWalkerhttps://github.com/NathanWalker
mainhttps://github.com/NativeScript/NativeScript/tree/main
fix/ios-nsdata-buffer-ownershiphttps://github.com/NativeScript/NativeScript/tree/fix/ios-nsdata-buffer-ownership
Conversation 2 https://github.com/NativeScript/NativeScript/pull/11370
Commits 2 https://github.com/NativeScript/NativeScript/pull/11370/commits
Checks 8 https://github.com/NativeScript/NativeScript/pull/11370/checks
Files changed https://github.com/NativeScript/NativeScript/pull/11370/files
Please reload this pagehttps://github.com/NativeScript/NativeScript/pull/11370/files
fix(core): iOS double free of V8-owned buffers; getRandomValues view handling https://github.com/NativeScript/NativeScript/pull/11370/files#top
Show all changes 2 commits https://github.com/NativeScript/NativeScript/pull/11370/files
eea1fd2 fix(core): stop donating V8-owned buffers to Foundation on iOS edusperoni Aug 27, 2026 https://github.com/NativeScript/NativeScript/pull/11370/commits/eea1fd2e48c5b8e299eca52358b84db725802bcc
b8ba488 fix(core): keep getRandomValues within the caller's view edusperoni Aug 27, 2026 https://github.com/NativeScript/NativeScript/pull/11370/commits/b8ba4888e9e1c65171654653394d7dc8bba7685f
Clear filters https://github.com/NativeScript/NativeScript/pull/11370/files
Please reload this pagehttps://github.com/NativeScript/NativeScript/pull/11370/files
Please reload this pagehttps://github.com/NativeScript/NativeScript/pull/11370/files
file-system-access.ios.spec.ts https://github.com/NativeScript/NativeScript/pull/11370/files#diff-c5533666cd0f861545ebfe16b4a3b05ae920fbf7e8d25240e269f42817b67f39
file-system-access.ios.ts https://github.com/NativeScript/NativeScript/pull/11370/files#diff-632981e86930a2ad08c2fe7645cac1e8993e92bcc622b30e50374345c525e3ed
vitest.setup.ts https://github.com/NativeScript/NativeScript/pull/11370/files#diff-ddf6541d9d5628e1067fc508b94fdd4fa700d5af4f6ebcc6438dda0115b8d371
index.spec.ts https://github.com/NativeScript/NativeScript/pull/11370/files#diff-f63784693e3aeec3845163bbcd54c6f3c9806c35138803e883160f586a9e9b47
index.ts https://github.com/NativeScript/NativeScript/pull/11370/files#diff-265a07f9fac942fea173b96161b7ecb1d40d0cfd773be9c9cc1b650ad7059633
packages/core/file-system/file-system-access.ios.spec.tshttps://github.com/NativeScript/NativeScript/pull/11370/files#diff-c5533666cd0f861545ebfe16b4a3b05ae920fbf7e8d25240e269f42817b67f39
View file https://github.com/NativeScript/NativeScript/blob/b8ba4888e9e1c65171654653394d7dc8bba7685f/packages/core/file-system/file-system-access.ios.spec.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/NativeScript/pull/11370/{{ revealButtonHref }}
packages/core/file-system/file-system-access.ios.tshttps://github.com/NativeScript/NativeScript/pull/11370/files#diff-632981e86930a2ad08c2fe7645cac1e8993e92bcc622b30e50374345c525e3ed
View file https://github.com/NativeScript/NativeScript/blob/b8ba4888e9e1c65171654653394d7dc8bba7685f/packages/core/file-system/file-system-access.ios.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/NativeScript/pull/11370/{{ revealButtonHref }}
https://github.com/NativeScript/NativeScript/pull/11370/files#diff-632981e86930a2ad08c2fe7645cac1e8993e92bcc622b30e50374345c525e3ed
https://github.com/NativeScript/NativeScript/pull/11370/files#diff-632981e86930a2ad08c2fe7645cac1e8993e92bcc622b30e50374345c525e3ed
packages/core/vitest.setup.tshttps://github.com/NativeScript/NativeScript/pull/11370/files#diff-ddf6541d9d5628e1067fc508b94fdd4fa700d5af4f6ebcc6438dda0115b8d371
View file https://github.com/NativeScript/NativeScript/blob/b8ba4888e9e1c65171654653394d7dc8bba7685f/packages/core/vitest.setup.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/NativeScript/pull/11370/{{ revealButtonHref }}
https://github.com/NativeScript/NativeScript/pull/11370/files#diff-ddf6541d9d5628e1067fc508b94fdd4fa700d5af4f6ebcc6438dda0115b8d371
https://github.com/NativeScript/NativeScript/pull/11370/files#diff-ddf6541d9d5628e1067fc508b94fdd4fa700d5af4f6ebcc6438dda0115b8d371
packages/core/wgc/crypto/index.spec.tshttps://github.com/NativeScript/NativeScript/pull/11370/files#diff-f63784693e3aeec3845163bbcd54c6f3c9806c35138803e883160f586a9e9b47
View file https://github.com/NativeScript/NativeScript/blob/b8ba4888e9e1c65171654653394d7dc8bba7685f/packages/core/wgc/crypto/index.spec.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/NativeScript/pull/11370/{{ revealButtonHref }}
packages/core/wgc/crypto/index.tshttps://github.com/NativeScript/NativeScript/pull/11370/files#diff-265a07f9fac942fea173b96161b7ecb1d40d0cfd773be9c9cc1b650ad7059633
View file https://github.com/NativeScript/NativeScript/blob/b8ba4888e9e1c65171654653394d7dc8bba7685f/packages/core/wgc/crypto/index.ts
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/NativeScript/pull/11370/{{ revealButtonHref }}
https://github.com/NativeScript/NativeScript/pull/11370/files#diff-265a07f9fac942fea173b96161b7ecb1d40d0cfd773be9c9cc1b650ad7059633
Please reload this pagehttps://github.com/NativeScript/NativeScript/pull/11370/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.