René's URL Explorer Experiment


Title: fix: typed array arguments leak and type confusion by edusperoni · Pull Request #2102 · NativeScript/android · GitHub

Open Graph Title: fix: typed array arguments leak and type confusion by edusperoni · Pull Request #2102 · NativeScript/android

X Title: fix: typed array arguments leak and type confusion by edusperoni · Pull Request #2102 · NativeScript/android

Description: Description Memory-safety and robustness bugs in how JS arguments are converted for Java calls. Each fix has a spec that crashed or failed on the test app before this change. 1. Typed arrays passed to object parameters leaked, then aborted the process. Passing an ArrayBuffer, SharedArrayBuffer, typed array or DataView to an object parameter (ByteBuffer, Object, channel.read(new ArrayBuffer(n)), …) wraps its memory in a direct Java buffer. The converter also took a JNI global reference to that buffer and never deleted it. As a result: the Java buffer could never be collected; its link kept the JS typed array, and so the V8 backing store, alive forever; once 51200 buffers had been passed, ART aborted with global reference table overflow (max=51200). Core reaches this in file-system-access.android.ts (readBufferSync, writeBufferSync, writeBufferAsync). The global ref was never needed for lifetime. The buffer is registered in the object table and linked to the JS object, which keeps the JS object, and with it the memory, alive for as long as Java holds the buffer. This is the same mechanism every other wrapper relies on. The conversion now: drops the global ref; deletes every local ref it creates (it used to leak ~5 per call); looks up the ByteBuffer/ByteOrder method ids and the native byte order once, instead of on every call; is shared by JsArgConverter and JsArgToArrayConverter instead of duplicated in both; throws a JS error for a buffer over 2 GiB, which NewDirectByteBuffer cannot represent and ART aborts on. 2. Typed arrays passed to array parameters were type confusion. When the call's signature is already resolved, the same code handed the direct buffer to an array parameter. Two examples: java.nio.ByteBuffer.wrap(u8), where wrap(byte[]) is the only one-argument overload; java.lang.String.format("%s", f32), whose varargs parameter is Object[]. Without CheckJNI (release builds) Java then uses a DirectByteBuffer as an array. Debug builds abort: JNI ERROR (app bug): attempt to pass an instance of java.nio.DirectByteBuffer as argument 1 to java.nio.ByteBuffer java.nio.ByteBuffer.wrap(byte[]) JNI ERROR (app bug): attempt to pass an instance of java.nio.ByteBufferAsFloatBuffer as argument 2 to java.lang.String java.lang.String.format(java.lang.String, java.lang.Object[]) The value is now copied into a new Java array of the parameter's type, which is the same copy semantics plain JS arrays already have: Parameter Copied as is (one SetArrayRegion) byte[] Int8Array, Uint8Array, Uint8ClampedArray, ArrayBuffer, SharedArrayBuffer, DataView short[], char[] Int16Array, Uint16Array (code units for char[]) int[] Int32Array, Uint32Array long[] BigInt64Array, BigUint64Array float[] Float32Array double[] Float64Array Any other typed array is converted element by element, exactly like a plain JS array holding the same numbers. For example: Float64Array → int[] truncates through ToInt32; Uint8Array → boolean[] maps non-zero values to true; Int32Array → Object[] boxes each element. These combinations throw Cannot convert to at index N: a BigInt array for anything but long[]; an ArrayBuffer/DataView for anything but byte[]; any typed array for a nested array type such as int[][]. Overload resolution is unchanged. Whether a typed array should select a byte[] overload among several candidates is a separate decision. This PR only fixes the conversion once the signature is resolved. 3. Converting a large JS array to a primitive array overflowed the stack. ConvertJavaScriptArray built the Java array's contents in a stack array (VLA) sized by the JS array's length. A 4M-element array passed to int[] (16 MB) overflowed the main thread's stack, and worker threads have much smaller stacks. The contents are now built in a heap buffer. 4. A reused typed array could lose its Java buffer for good. This sequence broke the typed array for every later Java call: JS drops a typed array, and its buffer becomes weakly held on the Java side. Java hands the same buffer back to JS, which gets the original typed array. Java lets go of the buffer and it is collected. JS passes the typed array to Java again, and the call fails with Failed to get Java object by ID ... Attempt to use cleared object reference. Now, when a typed array's link points at a collected buffer, the runtime asks Java to confirm that the buffer is gone (Runtime.releaseIfCollected). Only then does it drop the stale registrations on both sides (the Java object table entry and the native link state) and link a new buffer over the same memory. A link whose buffer Java still holds is never released, since that would leave the buffer pointing at memory nothing keeps alive. 5. Unconvertible JS array elements aborted the process. Converting a plain JS array to a Java array used ToChecked()/ToLocalChecked() on every element read. A BigInt or Symbol element, a throwing getter or a throwing valueOf therefore aborted with SIGTRAP. These now throw Cannot convert array to at index N: , for example ... [J at index 0: TypeError: Cannot convert a BigInt value to a number. Arrays reject BigInt elements because scalar long parameters already reject BigInt. The scalar error message used to be empty because the message buffer was never filled; it now reads Cannot convert bigint to J at index N. 6. Over-long arrays aborted the process. A JS array or typed array longer than a Java array can be (more than 2^31 − 1 elements, for example a sparse [] with length = 2 ** 31) now fails with the usual conversion error instead of aborting. Known hazards, not addressed here: the Java buffer points straight at the V8 backing store. If JS detaches that ArrayBuffer (transfer(), or a transfer through postMessage) or shrinks a resizable one while Java still holds the buffer, Java reads freed or stale memory. This is unchanged by this PR. Does your commit message include the wording below to reference a specific issue in this repo? No issue. Related Pull Requests None. Does your pull request have unit tests? Yes. testTypedArrayArgs.js has 18 specs, with a helper class com.tns.tests.TypedArrayArgs that has one single-overload method per array parameter type. The specs cover: copy semantics for ByteBuffer.wrap(Uint8Array); view offsets and lengths; every same-layout pairing; element-wise conversion matching plain arrays, including Object[] parameters; the rejected combinations; empty typed and plain arrays; 60,000 distinct typed arrays to an Object parameter, and as Object[] elements; the Java buffer being collectable after JS drops the typed array; a held buffer's memory staying valid after JS drops the typed array and GC runs; a 4M-element JS array to int[]; relinking a reused typed array after Java collected its buffer; BigInt, Symbol, throwing-getter and throwing-valueOf elements, plus BigInt to a scalar long; an array longer than a Java array can be. Verified on an API 36 arm64 emulator (debug build, CheckJNI on). Scenario Before After ByteBuffer.wrap(new Uint8Array(...)) CheckJNI abort (above) heap ByteBuffer over a copy String.format("%s", new Float32Array(2)) CheckJNI abort (above) formats the boxed elements 60,000 × capacityOf(new Uint8Array(16)) global reference table overflow (max=51200) at ~51,200 passes in ~0.2 s totalCapacity(Object[60000] of Float32Array) global reference table overflow (max=51200) passes WeakReference to the buffer of a dropped Uint8Array, after GC never cleared (40 GC rounds) cleared after the first round 4M-element JS array → int[] SIGSEGV, "stack pointer is in a non-existent map; likely due to stack overflow" passes Reused typed array after Java collected its buffer Attempt to use cleared object reference (fails on the first run, every run) relinked; Java sees a 3-byte buffer echoLongs([1n, 2n]), echoInts([1, Symbol()]), an element getter that throws SIGTRAP (V8 fatal from ToChecked) JS error naming the cause java.lang.Long.toHexString(5n) throws with an empty message Cannot convert bigint to J at index 0 Sparse array with length = 2 ** 31 → int[] SIGABRT Cannot convert array to [I at index 0 Full suite (./gradlew runtestsAndVerifyResults): 1545 specs, 0 failures. That is the 1527 existing specs plus the 18 new ones. Summary by CodeRabbit New Features JavaScript typed arrays and array buffers can now be passed to Java methods as compatible primitive arrays or buffers. Typed-array views and buffers support conversion to Java arrays, including element-by-element conversion when types differ. Buffer views preserve their offsets, and oversized inputs are rejected. Tests Added coverage for typed-array and buffer conversions, empty and large inputs, buffer references, and conversion errors.

Open Graph Description: Description Memory-safety and robustness bugs in how JS arguments are converted for Java calls. Each fix has a spec that crashed or failed on the test app before this change. 1. Typed arrays passed...

X Description: Description Memory-safety and robustness bugs in how JS arguments are converted for Java calls. Each fix has a spec that crashed or failed on the test app before this change. 1. Typed arrays passed...

Opengraph URL: https://github.com/NativeScript/android/pull/2102

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:887fedcc-b2c0-7942-06dc-f55f0a0d9e83
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idCD68:2D2F2F:19A76B5:20D7ABC:6B01383C
html-safe-noncebb8053e586bb7064f6c7cf4bed0ebb524332210e70308718802004cfc096767d
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRDY4OjJEMkYyRjoxOUE3NkI1OjIwRDdBQkM6NkIwMTM4M0MiLCJ2aXNpdG9yX2lkIjoiMjg0MjI5NTcxOTM4MzY2MDQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac697e8e34ea1c5de785a489008dfbca2b2d766ab36691f904cdfde886832e9611
hovercard-subject-tagpull_request:5253226145
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/android/pull/2102/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:altDescription Memory-safety and robustness bugs in how JS arguments are converted for Java calls. Each fix has a spec that crashed or failed on the test app before this change. 1. Typed arrays passed...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/NativeScript/android git https://github.com/NativeScript/android.git
octolytics-dimension-user_id7392261
octolytics-dimension-user_loginNativeScript
octolytics-dimension-repository_id29137950
octolytics-dimension-repository_nwoNativeScript/android
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id29137950
octolytics-dimension-repository_network_root_nwoNativeScript/android
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/android/pull/2102/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FNativeScript%2Fandroid%2Fpull%2F2102%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%2Fandroid%2Fpull%2F2102%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%2Fandroid
Reloadhttps://github.com/NativeScript/android/pull/2102/files
Reloadhttps://github.com/NativeScript/android/pull/2102/files
Reloadhttps://github.com/NativeScript/android/pull/2102/files
NativeScripthttps://github.com/NativeScript
androidhttps://github.com/NativeScript/android
Codehttps://github.com/NativeScript/android
Issues106 (106)https://github.com/NativeScript/android/issues
Pull requests24 (24)https://github.com/NativeScript/android/pulls
Actionshttps://github.com/NativeScript/android/actions
Projectshttps://github.com/NativeScript/android/projects
Wikihttps://github.com/NativeScript/android/wiki
Security and qualityhttps://github.com/NativeScript/android/security
Insightshttps://github.com/NativeScript/android/insights
Sign up for GitHub https://github.com/signup?return_to=%2FNativeScript%2Fandroid%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2FNativeScript%2Fandroid%2Fissues%2Fnew%2Fchoose
edusperonihttps://github.com/edusperoni
mainhttps://github.com/NativeScript/android/tree/main
fix/typed-array-arg-memoryhttps://github.com/NativeScript/android/tree/fix/typed-array-arg-memory
Conversation 7 https://github.com/NativeScript/android/pull/2102
Commits 2 https://github.com/NativeScript/android/pull/2102/commits
Checks 8 https://github.com/NativeScript/android/pull/2102/checks
Files changed https://github.com/NativeScript/android/pull/2102/files
Please reload this pagehttps://github.com/NativeScript/android/pull/2102/files
fix: typed array arguments leak and type confusion https://github.com/NativeScript/android/pull/2102/files#top
Show all changes 2 commits https://github.com/NativeScript/android/pull/2102/files
c0e6be7 fix: typed array arguments leak and type confusion edusperoni Nov 11, 2026 https://github.com/NativeScript/android/pull/2102/commits/c0e6be7722b0a372cfc6a7ee79d2331008f4bab8
8524b93 fix: relink collected buffers; throw for unconvertible array elements edusperoni Nov 11, 2026 https://github.com/NativeScript/android/pull/2102/commits/8524b936fd06a40eb6f5e58292241329a834297b
Clear filters https://github.com/NativeScript/android/pull/2102/files
Please reload this pagehttps://github.com/NativeScript/android/pull/2102/files
Please reload this pagehttps://github.com/NativeScript/android/pull/2102/files
mainpage.js https://github.com/NativeScript/android/pull/2102/files#diff-b7fd6c22bfc29391e9e3ed935d6c6194b1ad595c7592690229952b5ddb99c0d5
testTypedArrayArgs.js https://github.com/NativeScript/android/pull/2102/files#diff-35e1421ebd379b3eebb4bfb0329ad0f287633a074ec59892efba7a81848a56a5
TypedArrayArgs.java https://github.com/NativeScript/android/pull/2102/files#diff-8a4e439f9dec3ec8abbf64418c43384f57b2e125ef9bf2595ee5b890841ffe9e
JsArgConverter.cpp https://github.com/NativeScript/android/pull/2102/files#diff-9b41f905739990783e7f543f4c38aab34593873cf03762c959d6c3c7b6e991b7
JsArgConverter.h https://github.com/NativeScript/android/pull/2102/files#diff-bdd1e3debf725d5c60ef05e04e14346e55e103c6650314a49c83bf3d0c40cce6
JsArgToArrayConverter.cpp https://github.com/NativeScript/android/pull/2102/files#diff-2893b81a974ae0a84357d112dd872c8c7f3f3c74342ed15f25596e8f928e6ebf
ObjectManager.cpp https://github.com/NativeScript/android/pull/2102/files#diff-0591ab8dc271af7e8ef11fabf0642e44b932f38003bd07a3696de149a02b2c9b
ObjectManager.h https://github.com/NativeScript/android/pull/2102/files#diff-d491cf1566875df8740b3e9d732ac891286a776623aad17b249b36781ac7047d
Runtime.java https://github.com/NativeScript/android/pull/2102/files#diff-cf9bb4e9ca1a476cacd6e270fc8bcd12c71f89d52d272915bc99df57b3581f59
test-app/app/src/main/assets/app/mainpage.jshttps://github.com/NativeScript/android/pull/2102/files#diff-b7fd6c22bfc29391e9e3ed935d6c6194b1ad595c7592690229952b5ddb99c0d5
View file https://github.com/NativeScript/android/blob/8524b936fd06a40eb6f5e58292241329a834297b/test-app/app/src/main/assets/app/mainpage.js
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/android/pull/2102/{{ revealButtonHref }}
https://github.com/NativeScript/android/pull/2102/files#diff-b7fd6c22bfc29391e9e3ed935d6c6194b1ad595c7592690229952b5ddb99c0d5
https://github.com/NativeScript/android/pull/2102/files#diff-b7fd6c22bfc29391e9e3ed935d6c6194b1ad595c7592690229952b5ddb99c0d5
test-app/app/src/main/assets/app/tests/testTypedArrayArgs.jshttps://github.com/NativeScript/android/pull/2102/files#diff-35e1421ebd379b3eebb4bfb0329ad0f287633a074ec59892efba7a81848a56a5
View file https://github.com/NativeScript/android/blob/8524b936fd06a40eb6f5e58292241329a834297b/test-app/app/src/main/assets/app/tests/testTypedArrayArgs.js
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/android/pull/2102/{{ revealButtonHref }}
test-app/app/src/main/java/com/tns/tests/TypedArrayArgs.javahttps://github.com/NativeScript/android/pull/2102/files#diff-8a4e439f9dec3ec8abbf64418c43384f57b2e125ef9bf2595ee5b890841ffe9e
View file https://github.com/NativeScript/android/blob/8524b936fd06a40eb6f5e58292241329a834297b/test-app/app/src/main/java/com/tns/tests/TypedArrayArgs.java
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/NativeScript/android/pull/2102/{{ revealButtonHref }}
Please reload this pagehttps://github.com/NativeScript/android/pull/2102/files
Please reload this pagehttps://github.com/NativeScript/android/pull/2102/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.