Repository navigation
fix: bound --gpu sizes before the cast, mask U32 host arguments (#2348, #2347) - #2349
Open
Giulio2002 wants to merge 2 commits into
Open
Giulio2002 wants to merge 2 commits into
Giulio2002 wants to merge 2 commits into
Conversation
…lang#2348) The C runtime cast n * mul to u64 before checking it, so a size past 2^64 bytes (999999999999GB, 1e400GB) was an out-of-range double to u64 cast: UB, saturating to a 16 EiB request on arm64 that then failed as "reservation failed". The size is now kept as a double and becomes mem only when it is a well-formed size in [16384, 2^64). The JS runtime takes the same bound, so both lanes reject the same sizes, and its regex reads the digits as [\d.]* (same language, still linear). Fixes bendlang#2348 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
host() coerced Char, String, Nat and F32 arguments at a .mjs edge but passed a U32 through as is, so U32.show(2^32) printed "4294967296", U32.show(-1) printed "/" and U32.is_zero(2^32) was false while U32.add had already treated it as 0. A U32 argument (and a foreign U32 answer) now comes in as x >>> 0, the same mask the U32 operations use. Fixes bendlang#2347 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2348 and #2347, one commit each.
#2348:
--gpusize past 2^64 bytesRepro on main (6180be5),
tiny.bendfrom the issue, built with-fsanitize=undefined,float-cast-overflow:Fix: the C
--gpuarm keeps the size as a double and setsmemonly for a well formed size in [16384, 2^64), so no out-of-range cast happens and an oversize size gets the usual "expected on, off or a size like 4GB after --gpu". The JS runtime takes the same upper bound, so both lanes accept and reject the same sizes (checked on 19 edge inputs, including17179869183GBaccepted,17179869184GB,1e400GB,nanGB,-4GB,.GBrejected). Its regex reads the number as[\d.]*, the same language as before, andruntime_gpu_invalidstill passes.The arm is restructured (
gpu = strcmp(v, "off") != 0, one error branch) so comp.ts stays under its 66k ttok cap: 65997 after both commits, 65989 before.After: no UBSan report, exit 1 with the flag error, and a real GPU build of
tests/run/gpu_mark.bendnow rejects999999999999GBinstead of dying with "reservation failed".#2347: U32 argument from a JS caller
Repro on main,
host_u32.bendand its caller from the issue:Fix:
host()masks a U32 coming in withx >>> 0, like it rounds an F32 withMath.fround. After:which matches the issue's
expected.bend. I went with masking rather than a throwingu32_in: it is what the U32 ops already do, it matches the F32 edge, and it needs no new error text under the cap. Happy to switch if you'd rather fail-stop.The Nat remark in #2347 (
nat_inbounds at 2^53, not 2^48-1) is left alone: #1656,nat_host_exportandnat_host_boundspin 2^53 as the host range on purpose.Tests
tests/io/runtime_gpu_huge: builds a program as C and JS, checks both reject999999999999GB,17179869184GB,1e400GBand accept17179869183GB,4GB.tests/io/u32_host_export: 2^32, -1, 2^32+5 throughshow,is_zeroandadd, one call and curried.Both fail on main (exit codes 1 and 2) and pass here. These also still pass:
runtime_gpu_invalid,f32_host_export,nat_host_export,nat_host_bounds,nat_host_neg,u32_to_f32_host_zero. I could not run the cluster gates from here. I ran these locally under bun 1.4.5 on Darwin arm64.🤖 Generated with Claude Code