Repository navigation
Conversation
|
Updated 5:10 AM PT - Oct 22nd, 2026
✅ @robobun, your commit 35e913cc6e12a2c2c04deb64ca5168726cebb305 passed in 🧪 To try this PR locally: bunx bun-pr 42136That installs a local version of the PR into your bun-42136 --bun |
|
Status Reproduced on Bun 1.4.3: The two new tests in This PR is rebased onto main and no longer depends on #42112. It uses |
There was a problem hiding this comment.
Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.
LGTM — swaps the u64-capped parse for the shared radix→double helper already used by the lexer and JSONC parser, with thorough boundary and tie-to-even coverage. The inline .repeat note is a convention nit only; string lengths here are ≤256 so it's not load-bearing.
Extended reasoning...
Overview
The PR changes scan_hex_number() in src/parsers/json5.rs to route hex digit runs through bun_core::fmt::parse_power_of_two_radix_digits(digits, 16) instead of parse_int::<u64>. This lifts the artificial 64-bit ceiling and matches ES HexIntegerLiteral / Number("0x…") semantics, which is what the reference json5 npm package does. The scanner loop above already guarantees the slice contains only ASCII hex digits and is non-empty, so the helper's precondition is satisfied and the removed error branch was genuinely unreachable for well-formed digit runs. The same helper is already the established pattern in src/js_parser/lexer.rs and src/parsers/json_stage2.rs, so this is a consistency fix as much as a correctness one.
Test additions in test/js/bun/json5/json5.test.ts cover the variant matrix well: values just past 2^64, signed forms, uppercase 0X with leading zeros, embedded-in-object/array contexts, the Number.MAX_VALUE / Infinity boundary at both sides of the half-ulp tie, and explicit round-half-to-even cases at 2^53 and 2^64 with a Number(BigInt(...)) oracle loop. The deleted "hex number too large" negative test's exact input (0xFFFFFFFFFFFFFFFFFF) reappears as a positive .toBe(2 ** 72) assertion, satisfying the "every deleted test needs a stated replacement" rule.
Security risks
None. This is numeric-literal parsing with no allocation proportional to input beyond what the scanner already advanced; the helper takes a bounded slice of pre-validated hex digits. No untrusted-length arithmetic, no I/O, no auth/crypto surface.
Level of scrutiny
Low-to-moderate. Five-line Rust change swapping one bun_core::fmt helper for another that's already exercised on identical input shapes elsewhere in the tree; the interesting correctness work (correct rounding) lives in the stacked #42112 helper, not here. No CODEOWNERS entry covers src/parsers/ or test/js/bun/json5/.
Other factors
The one confirmed finding is a test-harness convention nit (.repeat(n) vs Buffer.alloc(n, fill).toString()) at n ≤ 256, which the finding itself notes has negligible cost. It doesn't affect correctness or CI runtime meaningfully and doesn't warrant holding the PR. No prior reviews or outstanding objections in the timeline; exit reason was dry_streak.
|
Looked at the review. The one note was the optional |
329973e to
0104327
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
WalkthroughJSON5 hexadecimal parsing now supports literals beyond the ChangesJSON5 hexadecimal parsing
Suggested reviewers: Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to
|
There was a problem hiding this comment.
LGTM — small, self-contained change that routes JSON5 hex literals through the shared RadixInteger helper, and the earlier .repeat nit is addressed with Buffer.alloc.
What was reviewed:
scan_hex_number(src/parsers/json5.rs:1038-1046): the scanner'sis_ascii_hexdigitpre-filter andto_digit(16)accept exactly the same bytes, sofilter_mapdrops nothing;push_digit(4, ..)only starts dropping onceleadingholds 61+ bits, so the sticky-bit rounding into_f64is correct and all-zero digit runs stay exact 0.- Sign and
-Infinityare applied by the callerscan_signed_value, so-0x1followed by 256 zeros gives-Infinityas the test asserts; theas_writtenearly return used bybun lintis untouched and lint already reports such literals as evaluating to Infinity. - The deleted "hex number too large" test is replaced by a positive assertion on the same literal plus a deterministic (seeded) sweep against
Number(BigInt)that guards against an empty case list and skips0nso-0is not compared with+0.
Extended reasoning...
The diff touches one function in src/parsers/json5.rs (8 lines) and test/js/bun/json5/json5.test.ts, replacing a u64 parse-with-overflow-error by the existing bun_core::fmt::RadixInteger used by four sibling radix-number sites, so hex literals of any width become the nearest double or Infinity as json5 and ECMAScript specify. It touches no security-sensitive surface; the input is already bounded to hex digits by the scanner and no allocation is added. The new commit addresses the only prior inline comment, no other reviewer objection is recorded, the changed files have no CODEOWNER, the hunt exited by dry_streak with no findings, and the tests cover 2^64 boundaries, both signs, the finite/Infinity limit, and a seeded rounding sweep.
…d of rejecting them
Bun.JSON5.parse("0x1ffffffffffffffff") threw "Invalid hex number" because
scan_hex_number() parsed the digits into a u64. A JSON5 hex number is an
ECMAScript HexIntegerLiteral, a Number of any magnitude, and the json5
package returns Number("0x...") for it. Collect the digits in
bun_core::fmt::RadixInteger, which the JavaScript lexers and the JSONC
parser already use. It rounds once to the nearest double, ties to even, and
gives Infinity past Number.MAX_VALUE.
0104327 to
35e913c
Compare
Problem
Bun.JSON5.parse("0x1ffffffffffffffff")throwsSyntaxError: JSON5 Parse error: Invalid hex number. Thejson5package and the JS literal give 36893488147419103000 (2^65)..json5imports fail the same way.scan_hex_number()(src/parsers/json5.rs:1039) parses the digits withparse_int::<u64>and maps the overflow toInvalidHexNumber.Fix
scan_hex_number()collects the digits inbun_core::fmt::RadixInteger(Round long hexadecimal, octal and binary literals to the nearest double #45290), as the JavaScript lexers and the JSONC parser do. The result is the nearest double, orInfinitypastNumber.MAX_VALUE.u64 as f64cast also rounded once.error messages > hex number too large, which pinned the throw.test/js/bun/json5/json5.test.ts(both new tests fail on 1.4.3). Alsojson5-test-suite.test.ts,jsonc.test.tsand the JSON5 tests oftest/cli/lint/js-parsers.test.ts.Background
NumericLiterals, so a hex number has no digit limit. Thejson5package returnsNumber("0x..."): the nearest double, ties to even.RadixIntegerkeeps the leading digits in au64and counts the bits of the rest.to_f64()rounds once.u64fast path, withRadixIntegeronly on overflow: two paths, and slower from three digits up.Downsides
SyntaxErrornow gets a rounded Number orInfinity.bun_parsers.Notes
parse_power_of_two_radix_digits, a helper backed by JSC that Bump WebKit (oven-sh/WebKit#597 preview): parseInt, Number() and eval round binary, octal and hex digits to the nearest double #42112 added. Round long hexadecimal, octal and binary literals to the nearest double #45290 then putRadixIntegeron main and Bump WebKit (oven-sh/WebKit#597 preview): parseInt, Number() and eval round binary, octal and hex digits to the nearest double #42112 dropped its helper. This PR is now based on main and needs no WebKit change.bun lintalready states this behavior.json/no-unsafe-valuesreports "The number '+0xf..f' will evaluate to Infinity" for a 300-digit hex number in a.json5file (test/cli/lint/js-parsers.test.ts). On main,Bun.JSON5.parsethrows for that number.integersThatNeedRounding()(test/harness.ts, from Round long hexadecimal, octal and binary literals to the nearest double #45290), adds each with-and with+, and compares withNumber(BigInt(text)). That is 989 numbers, 203 of the 331 unsigned ones are 2^64 or more.json5@2.2.3on node v26.3.0 returns the expected value for each explicit assertion and for all 989 numbers of the sweep.Number(BigInt)gives the same bits in JSC and in V8 for them.Bun.JSON5.parse("0x" + digits)equalsNumber(BigInt("0x" + digits))for 52,773 digit strings, each also negated: 0 mismatches. The strings are random runs of 1 to 300 digits, a tie-biased band of 53 to 80 bits,2^k ± smallwith zero and non-zero tails, theNumber.MAX_VALUE/Infinityboundary, and one number of 100,001 digits.bun_parsers(the setup ofscripts/bench-json-rust.sh) parses an array of 1,000 copies of one hex number 2,000 times.perf_event_opencounts the user-space instructions. Repeated runs agree within 700 instructions of 1.3 billion. Per number, before and after:0x0320.23 and 341.23,0xF331.23 and 341.23,0xFF379.23 and 380.23,0xFFF427.23 and 419.23,0xFFFF475.23 and 458.23,0xFFFFFF571.23 and 536.23,0xDEADBEEF667.23 and 614.23, 12 digits 859.23 and 770.23, 16 digits 1051.23 and 926.23. Each count is the whole cost of one array element.perf,valgrindandbloatyare not installed in my environment, so the sizes come fromsize: text 605,095 and 605,047 bytes, data 25,008 and 25,016 bytes. These are not sizes of the releasebunbinary.powicall inRadixInteger::to_f64(). An early return fordropped_bits == 0there would remove it for all five users. This PR does not change the shared helper.test/cli/lint/js-parsers.test.tsone at a time: "lints JSON, JSONC and JSON5 without the eslint package", "a rejected file gets exactly one fatal problem", "accepts and rejects the right inputs", "follows the spec where the plugin's parser doesn't", "parses JSON5-only syntax in JSON5" and "all of the plugin's rules". All pass. Under my debug build the tests of that file exceed the 5 second limit when they run at once, and "many keys out of order, with comments" takes 7.4 seconds alone. So I ran them one at a time with a longer limit. I also ran thejson5case oftest/bundler/bundler_loader.test.ts.SourceTokens(theas_writtenmode thatbun lintreads tokens with) returns before the conversion, as before.Bun.YAML.parsereturns a string for a0xscalar of 2^64 or more (src/parsers/yaml.rs). That is a schema question for the YAML parser.RadixIntegerresolves it. The new tests build long digit runs withBuffer.alloc(n, "0").toString(), as the review of the first version asked.[human-review] gate passed · iteration 1 · 2 files touched
fails on main (without fix)
passes on PR (with fix)
diff hotspot
gate history · 1 passed · 0 rejected · iteration 1
evidence per changed file