Skip to content

Commit e2a805a

Browse files
author
Zachary Whitley
committed
docs(patches): carry jco #1574 — browser file read BigInt bounds coercion
Establish patches/jco/ + docs/upstream-patches.md as the register for compatibility patches carried locally against published upstream WASI / browser runtime layers. Adds the first entry: Patch: bytecodealliance/jco#1574 Reason: browser p2-shim file read BigInt bounds incompatibility (Uint8Array.slice rejects the canonical-ABI BigInt offset and length arguments) Scope: JCO preview2/browser shim only (packages/preview2-shim/lib/browser/filesystem.js Descriptor.read) Removal condition: first jco release containing #1574 or equivalent upstream fix (detected at apply time via 'typeof offset === "bigint"' against the browser filesystem.js source) Substrate impact: none — patch lives in the compatibility layer, not in any consumer's substrate code Carried so that any consumer of @tegmentum/wasi-polyfill picks up the corrected browser compatibility behavior without having to learn about JCO's browser BigInt bug or carry a private workaround. Patch file applies with: patch -p5 -d <shim-dir> < patches/jco/1574-coerce-browser-file-read-bounds-to-numbers.patch against a copy of @bytecodealliance/preview2-shim's browser build (verified on 0.18.0). See docs/upstream-patches.md for the active/retired patch register and the lifecycle of a carried patch. Signed-off-by: Zachary Whitley <zachary.whitley@tegmentum.ai>
1 parent 14a5322 commit e2a805a

2 files changed

Lines changed: 82 additions & 0 deletions

File tree

docs/upstream-patches.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# wasi-polyfill — upstream patches register
2+
3+
Local patches carried against published upstream WASI / browser
4+
runtime layers, with explicit removal conditions. These patches
5+
adapt **compatibility-layer behavior** — they are NOT Fiji
6+
substrate fixes and do not change Fiji's JVM/component
7+
semantics.
8+
9+
## Architectural boundary
10+
11+
| Layer | Responsibility |
12+
|---|---|
13+
| Fiji | JVM / component behavior |
14+
| **wasi-polyfill** | Runtime / browser / WASI compatibility |
15+
| Upstream (e.g. jco) | The published layer being patched |
16+
17+
Patches in `wasi-polyfill/patches/` are *temporary* by design.
18+
Each has a documented **removal condition** keyed to the
19+
upstream's release stream. When that condition is met, the
20+
patch is dropped on the next maintenance pass.
21+
22+
## Active patches
23+
24+
### jco #1574 — browser p2-shim file read BigInt bounds
25+
26+
- **Patch:** `wasi-polyfill/patches/jco/1574-coerce-browser-file-read-bounds-to-numbers.patch`
27+
- **Upstream:** [bytecodealliance/jco#1574](https://github.com/bytecodealliance/jco/pull/1574) (filed 2026-05-29; OPEN)
28+
- **Upstream issue:** [bytecodealliance/jco#1573](https://github.com/bytecodealliance/jco/issues/1573)
29+
- **Reason:** browser p2-shim file read BigInt bounds incompatibility (`Uint8Array.slice` rejects the canonical-ABI `BigInt` `offset` and `length` arguments)
30+
- **Scope:** JCO preview2 / browser shim only (`packages/preview2-shim/lib/browser/filesystem.js Descriptor.read`)
31+
- **Removal condition:** first `@bytecodealliance/preview2-shim` release containing #1574 or an equivalent upstream fix (detected at apply-time by `grep -q 'typeof offset === "bigint"'` against the browser `filesystem.js`)
32+
- **Fiji substrate impact:** **none**
33+
- **Applied by:** `scripts/portability/setup_beta13_browser.sh` (idempotent; skips if the upstream version already contains the fix)
34+
- **Carrying record opened:** 2026-05-29
35+
36+
## How to retire a patch
37+
38+
1. Upstream releases a version containing the fix.
39+
2. Update `package.json` `@bytecodealliance/preview2-shim` to that
40+
version.
41+
3. Re-run `scripts/portability/setup_beta13_browser.sh` — the
42+
detection grep matches and the patch is skipped cleanly.
43+
4. Delete the `.patch` file under `wasi-polyfill/patches/jco/`.
44+
5. Remove this section's entry from "Active patches" and add an
45+
entry under "Retired patches" with the release version that
46+
absorbed it.
47+
48+
## Retired patches
49+
50+
(none yet)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
From: Zachary Whitley <zachary.whitley@tegmentum.ai>
2+
Subject: [PATCH] fix(p2-shim): coerce browser file read bounds to numbers
3+
4+
Mirror of bytecodealliance/jco#1574. Apply locally against the
5+
@bytecodealliance/preview2-shim 0.18.0 browser implementation until
6+
the upstream fix ships in a published release.
7+
8+
When applied via patch(1), use -p5 with a directory holding the
9+
browser shim copy:
10+
patch -p5 -d <shim-dir> < 1574-coerce-browser-file-read-bounds-to-numbers.patch
11+
12+
See wasi-polyfill/docs/upstream-patches.md for the carrying-record.
13+
14+
---
15+
packages/preview2-shim/lib/browser/filesystem.js | 4 +++-
16+
1 file changed, 3 insertions(+), 1 deletion(-)
17+
18+
diff --git a/packages/preview2-shim/lib/browser/filesystem.js b/packages/preview2-shim/lib/browser/filesystem.js
19+
index 6c585ac1..6bf81913 100644
20+
--- a/packages/preview2-shim/lib/browser/filesystem.js
21+
+++ b/packages/preview2-shim/lib/browser/filesystem.js
22+
@@ -188,7 +188,9 @@ class Descriptor {
23+
24+
read(length, offset) {
25+
const source = getSource(this.#entry);
26+
- return [source.slice(offset, offset + length), offset + length >= source.byteLength];
27+
+ const off = typeof offset === "bigint" ? Number(offset) : offset;
28+
+ const len = typeof length === "bigint" ? Number(length) : length;
29+
+ return [source.slice(off, off + len), off + len >= source.byteLength];
30+
}
31+
32+
write(buffer, offset) {

0 commit comments

Comments
 (0)