|
4 | 4 | :toc: macro |
5 | 5 | :icons: font |
6 | 6 |
|
7 | | -This audit follows the #830 fix. The Unicode thread (#829) found several ways |
| 7 | +This audit follows the #830 fix. Findings 5 and 6 were added after the #829 thread reported them. The Unicode thread (#829) found several ways |
8 | 8 | the backends disagree. The owner asked whether any of the others needs the |
9 | 9 | same at-source treatment as the wasm heap/literal overlap. |
10 | 10 |
|
@@ -59,6 +59,16 @@ plausible-wrong result. |
59 | 59 | | Loud divergence (the reference interpreter) |
60 | 60 | | No |
61 | 61 | | #833 |
| 62 | + |
| 63 | +| A user fn named like a wasm-intercepted intrinsic is silently replaced |
| 64 | +| *Soundness hole*: silent wrong value |
| 65 | +| No |
| 66 | +| #836 (pinned `open (tracked)` in this PR) |
| 67 | + |
| 68 | +| An intrinsic used as a value (e.g. `len`) emits a bare name on Bun-ESM |
| 69 | +| Loud divergence, at the wrong phase |
| 70 | +| No |
| 71 | +| #837 |
62 | 72 | |=== |
63 | 73 |
|
64 | 74 | == 1. Core-wasm heap overlaps string literals (#830) |
@@ -198,6 +208,55 @@ Outside the box:: |
198 | 208 | Move the CLI's interpreter role onto `solo_cesk`. That would also unblock |
199 | 209 | #623. |
200 | 210 |
|
| 211 | +== 5. Wasm replaces a user function named like an intrinsic (#836) |
| 212 | + |
| 213 | +Reported by the #829 thread after the first version of this audit, and |
| 214 | +reproduced independently. |
| 215 | + |
| 216 | +Evidence:: |
| 217 | +On `main`, `fn string_sub(s: String, a: Int, b: Int) -> Int { 7 }` called from |
| 218 | +`main` prints `7` on the interpreter and on Bun-ESM, but `1024` on core wasm |
| 219 | +(`1040` with #830). That number is the heap address of the intrinsic's |
| 220 | +substring. `wasm-tools print` shows the user's function compiled as func 1, |
| 221 | +which `main` never calls. Cause: `gen_expr` in `lib/codegen.ml` intercepts 20 |
| 222 | +names by spelling (`ExprVar id when id.name = "…"`) before checking whether |
| 223 | +the name resolves to a user declaration. |
| 224 | + |
| 225 | +Classification:: |
| 226 | +*Soundness hole*: a silent wrong value on a supported path. This PR pins it |
| 227 | +in `docs/SOUNDNESS.adoc` as `open (tracked)` with an xfail pin, |
| 228 | +`test_wasm_intrinsic_shadow_xfail`. With the `string_sub` intercept removed, |
| 229 | +the pin flips to XPASS, which confirms it detects the hole. It is not fixed |
| 230 | +here: some arms deliberately intercept stdlib `extern fn`s, so each of the 20 |
| 231 | +arms needs auditing. |
| 232 | + |
| 233 | +Recommended fix (*most elegant and correct*):: |
| 234 | +Tag builtin calls at resolution and match on the tag in codegen, so a user |
| 235 | +declaration always shadows the builtin. |
| 236 | + |
| 237 | +Most dependable:: |
| 238 | +Add a per-arm `not (is_user_defined …)` guard, with one run test per name. |
| 239 | + |
| 240 | +Stop-gap:: |
| 241 | +Refuse a user top-level declaration that reuses an intercepted name on wasm. |
| 242 | + |
| 243 | +== 6. Intrinsics used as values on Bun-ESM (#837) |
| 244 | + |
| 245 | +Evidence:: |
| 246 | +`apply(len, "abc")` prints `3` on the interpreter. On Bun-ESM it fails with |
| 247 | +`ReferenceError: len is not defined` at run time. Core wasm refuses it at |
| 248 | +compile time (`UnboundVariable "len"`). |
| 249 | + |
| 250 | +Classification:: |
| 251 | +Loud divergence, at the wrong phase. This is the same class as #832. |
| 252 | + |
| 253 | +Recommended fix (*most elegant and correct*):: |
| 254 | +Eta-expand an intrinsic in value position in a shared pre-codegen pass, so |
| 255 | +it becomes first-class on every backend. |
| 256 | + |
| 257 | +Most dependable:: |
| 258 | +Refuse it at codegen on Bun-ESM, as wasm already does. |
| 259 | + |
201 | 260 | == Reaching beyond this repo |
202 | 261 |
|
203 | 262 | * #834 tracks rebuilding core-wasm artefacts built before #830 in other |
|
0 commit comments