Skip to content

[WTF] simdutf: the arm64 base64 decoder no longer takes "[" for a base64 character - #919

Merged
dylan-conway merged 3 commits into
mainfrom
claude/simdutf-arm64-base64-bracket
Oct 28, 2026
Merged

dylan-conway merged 3 commits into
mainfrom
claude/simdutf-arm64-base64-bracket

Conversation

@dylan-conway

@dylan-conway dylan-conway commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Problem

  • On arm64, simdutf's base64 decoder takes [ (0x5B) for a base64 character in the mode that accepts both alphabets (base64_default_or_url, with or without accept_garbage). It decodes it as the value 26. The scalar decoder and the x64 kernels reject it.
  • The same kernel then reads before its input: at the end it steps back over the characters it has staged, counts them with the scalar table, and does not count a staged [.
  • In Bun on arm64 (Buffer.from and Buffer#write with "base64" or "base64url", once the text has 64 characters):
const a = "QUJD".repeat(16);
Buffer.from(a + "[" + a, "base64").equals(Buffer.from(a + a, "base64")); // false, x64: true
Buffer.from("[[" + "!".repeat(62), "base64").toString("hex");            // "c1", x64: ""

Fix

simdutf's own fix, simdutf/simdutf@23556f1 (simdutf/simdutf#1062, released in v9.3.3), copied as it is. Five lines of arm64::to_base64_mask:

  • default_or_url: _ gets bit 0x10 instead of the bit it shared with +. lut_lo[0xF] goes from 0xa6 to 0xb6 and lut_hi[0xB] from 0x12 to 0x10, in both spellings of each literal. [ now gives 0xa2 & 0x10 = 0.
  • base64_url, Visual Studio spelling only: lut_hi[5] goes from 0x6 to 0x4, as the other spelling has it. No lane of this fork compiles that spelling.

The arm64 base64 section of simdutf_impl.cpp.h is byte for byte src/arm64/arm_base64.cpp of v9.0.0 with that commit's patch applied (patch on the v9.0.0 file, then cmp with the section).

Background

  • This is a bug of simdutf, not of how WebKit uses it. simdutf/simdutf@825887d ([WTF] Let the embedder key the string and integer hashes per process #783, first released in v7.1.0) wrote these tables; the ones before it rejected [.
  • The kernel looks a byte up by its low nibble (lut_lo) and by its upper five bits (lut_hi) and ANDs the two. 0 is an error, 1 is white space, above 1 is a base64 character. + (column B, row 5) and _ (column F, row 11) shared bit 1, so column B with row 11, which is [, passed too.
  • Bit 0x10 is the one X, Y and Z have in row 11. The only other row with it is row 8 (0x40 to 0x47), which has no column F.
  • No caller in JavaScriptCore or WTF uses default_or_url or an accept_garbage mode. Bun's Buffer decoder does.

Downsides

  • Nothing was built or run with these tables before the push. I read column F against all 16 rows and row 11 against its 8 columns: only [ changes. CI of this pull request compiles it; nothing in that CI decodes in this mode.
  • No test here. Upstream's tests (tests/base64_tests.cpp) are not part of what WebKit imports. Bun has one on the branch claude/bold-pasteur-owp24g (test/js/node/buffer.test.js), which goes in with the WebKit bump.
  • The walk back still has no lower bound, as upstream. It stays inside the input because the two tables agree again.
  • simdutf_impl.cpp.h is an imported file. An import of v9.3.3 or later brings the same lines.
Notes

Earlier commits of this pull request had a fix of our own: lut_lo[0xB] = 0xa4 (+ moved instead of _), a lower bound on the walk back in three kernels, and a TestWTF test. e6e8cd3 takes all of it out again. The measurements that this description used to list were of that version and say nothing about this one.

Seen on hardware, before any fix. simdutf master at e2a9551e on Apple silicon: the wrong results above, and AddressSanitizer reports heap-buffer-overflow, READ of size 1, 1 byte before a 64-byte input, at arm_base64.cpp:769.


Generated by Claude Code

…e64 character

In the mode that accepts both alphabets (base64_default_or_url), the arm64 kernel classifies a byte
by ANDing a table entry for its low nibble with one for its upper five bits. "+" (column B, row 5)
and "_" (column F, row 11) shared bit 1, so column B with row 11, which is "[", passed as well and
was decoded as the value 26. The scalar table rejects "[". "+" now uses bit 2, which "-" and "/"
already use in row 5 and which row 11 does not have.

At the end of the input the kernel steps back over the one to three characters it has staged but not
decoded. It counts them with the scalar table and had no lower bound, so a staged "[" was not counted
and the walk read before the input. With the table fixed the two classifiers agree on all 256 bytes.
The walk now also stops at the start of the input, in all six copies of the loop.

* Source/WTF/wtf/simdutf/simdutf_impl.cpp.h:
(simdutf::arm64::to_base64_mask):
(simdutf::arm64::compress_decode_base64):
(simdutf::haswell::base64::compress_decode_base64):
(simdutf::ppc64::base64::compress_decode_base64):
(simdutf::westmere::base64::compress_decode_base64):
(simdutf::lasx::compress_decode_base64):
(simdutf::lsx::compress_decode_base64):
@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 20 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: ec6c9b7a-84ff-4e81-a325-c9e7bca7d93d
Commits

Reviewing files that changed from the base of the PR and between cdce396 and 2838417.

Files selected for processing: 2
  • Source/WTF/wtf/simdutf/simdutf_impl.cpp.h
  • Tools/TestWebKitAPI/Tests/WTF/Base64.cpp
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

Beyond the inline findings, I walked the new default_or_url lut_lo[0xB] = 0xa4 against every lut_hi row: the only byte whose classification changes is 0x5B ("[", now rejected); "+" is still accepted via row 5 (0xa4 & 0x6 = 0x4) and rows 1/4/9/A/D/E are unaffected. I also checked the icelake rewind at simdutf_impl.cpp.h:27281 for the same under-run — it counts with the same is_eight_byte/code<=63 rule used to stage the chunk, so it is not affected by the arm64 miscount.

Extended reasoning...

The change edits only the vendored simdutf amalgamation: one lookup-table byte in the arm64 base64 classifier (both MSVC and non-MSVC spellings) and a lower-bound guard on the backtracking loop in six per-architecture copies of compress_decode_base64. It touches an input-parsing path that previously read before the input buffer, which is memory-safety sensitive. Two confirmed inline findings already signal human review is needed, so this body only records what else was examined and ruled out.

Additional findings (outside the current diff — GitHub can't attach inline comments there):

  • 🟣 Source/WTF/wtf/simdutf/simdutf_impl.cpp.h — The two spellings of the arm64 lookup tables now diverge in a second place that this PR leaves untouched, so the same base64_url input decodes differently per compiler. The non-MSVC lut_hi at simdutf_impl.cpp.h:17769 has row 5 = 0x4 and the MSVC one at 17757 has 0x6, and the PR synchronises only the lut_lo twins at 17723 and 17736. A cl.exe arm64 build accepts "/" in base64_url mode and a clang build rejects it. Fix: when editing the MSVC/non-MSVC twins, diff every pair (lut_lo, lut_hi, roll_lut, delta_asso) and make 17757 read 0x4 to match 17769.

    Why this was flagged

    Trigger: a base64_url decode containing "/" on an arm64 build compiled by regular Visual Studio. lut_lo[F] for base64_url is 0xa2 (17727/17739), so with the MSVC row 5 of 0x6 at 17757 the AND gives 0x2 (accepted) while the non-MSVC row 5 of 0x4 at 17769 gives 0 (error). The commit message and PR say both spellings of the literal were updated, which is true for lut_lo only; the lut_hi pair was not compared. The base branch has the same discrepancy, but this PR is the first to touch these twin tables and is the natural place to catch it; the fork's CLAUDE.md-noted convention is that the MSVC/non-MSVC initialisers must be kept in sync. Population: Windows arm64 builds with cl.exe; no CI lane in this fork covers them, so the divergence would only surface as user-visible different Buffer results between platforms.

    Verification: Pre-existing: triggers only when the arm64 kernel is compiled by regular cl.exe. In Source/WTF/wtf/simdutf/simdutf_impl.cpp.h the two spellings of lut_hi for base64_url differ at row 5 — 0x6 at 17757 vs 0x4 at 17769. A cl.exe arm64 build accepts "/" in base64url mode. Lines 17750-17775 are untouched by the PR, so the base already has the identical divergence.

…ls that are compiled

TestWTF runs on an arm64 machine in CI, so the mode that took "[" for a base64 character can be
tested here although nothing in WTF calls it. The test puts each byte outside the two alphabets into
a long input and expects it to be skipped. It fails without the table fix and names byte 91 alone.

The ppc64, lasx and lsx copies of the walk back are as imported again. No lane compiles them, so the
bound there was never compiled either. The arm64, haswell and westmere copies keep it.

The changed places have a comment, so that an import of a newer simdutf sees that they are local.

* Source/WTF/wtf/simdutf/simdutf_impl.cpp.h:
(simdutf::arm64::to_base64_mask):
(simdutf::arm64::compress_decode_base64):
(simdutf::haswell::base64::compress_decode_base64):
(simdutf::ppc64::base64::compress_decode_base64):
(simdutf::westmere::base64::compress_decode_base64):
(simdutf::lasx::compress_decode_base64):
(simdutf::lsx::compress_decode_base64):
* Tools/TestWebKitAPI/Tests/WTF/Base64.cpp:
(TestWebKitAPI::TEST(Base64, SIMDUTFDefaultOrURLAcceptGarbageSkipsOtherBytes)):

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed the updated push (table fix, bounded walk-back in three kernels, new TestWTF test) and found no bugs; because this is a local patch to a vendored SIMD decoder that now diverges from upstream simdutf in some kernel copies but not others, a human look at that policy choice is still worthwhile.

What was reviewed:

  • Walked the new arm64 default_or_url lut_lo/lut_hi pair for all 256 byte values against to_base64_default_or_url_value: they now agree everywhere (only '[' differed before), and bit 2 for '+' does not change the decoded values since default_or_url derives them from delta_asso/roll_lut, not the res bits.
  • Checked the bounded walk-back: inner guard keeps src >= srcinit+1 and the outer guard keeps the *(src-1) read in bounds; in the agreeing-tables case it steps over exactly the same bytes as before. The haswell/westmere kernels use the aqrit check_asso hash, not this lut scheme, so they are not affected by the '[' bug.
  • The PR description still says the bound is in "all six copies"; after 2838417 it is in arm64/haswell/westmere only (ppc64/lsx/lasx are back to the import), which matches the commit message but not the description.
  • Adjacent, pre-existing, not from this diff: the MSVC spelling of the base64_url lut_hi (simdutf_impl.cpp.h:17760) has row 5 = 0x6 where the non-MSVC spelling (17772) has 0x4; by my reading that lets '/' through in url mode on MSVC arm64 (decoding as 15). Not a CI lane here, but worth a glance while in these tables.
Extended reasoning...

The diff changes two lookup-table bytes in the arm64 NEON base64 classifier and adds a lower bound to the end-of-input walk-back loop in three of the six compress_decode_base64 copies in the vendored simdutf amalgamation, plus a new TestWTF test that exercises base64_default_or_url_accept_garbage with every non-alphabet byte at several positions in a 128-char input. The surface is a memory-safety fix (an out-of-bounds read before the input start) in third-party decoder code reached by Bun's Buffer base64 paths, not auth or injection. I verified the table against the scalar table for all 256 bytes and the bound logic by hand, the test will run on the arm64 Linux CI lane, and the earlier inline thread was resolved by the author with a reply. Deferring rather than approving because the change deliberately leaves the vendored file inconsistent across kernel copies (a divergence an importer of newer simdutf has to carry), the PR text is stale on that point, and the author states WebKit itself was not built with the change.

Copy link
Copy Markdown
Member Author

The red release check on 2838417 is not a failure of the change. The run was cancelled at 09:45 UTC while all of its lanes were still queued (77 jobs cancelled, none started), and release fails at "Publish or delete the draft" whenever that happens.

So this commit has not been built or tested by CI yet, and there is no preview release and no arm64 result for the new TestWTF test. It needs "Re-run all jobs". I am leaving that until the build of main (191c6a4), which is queued behind the same runners, has got through.


Generated by Claude Code

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Preview build of e6e8cd3: autobuild-preview-pr-919-e6e8cd37

simdutf fixed this in 23556f1 (simdutf/simdutf#1062, released in v9.3.3). This replaces our own fix
with theirs, so that the imported file differs from v9.0.0 only by what a newer import brings anyway.

Upstream gives '_' a bit of its own instead of '+': lut_lo[0xF] = 0xb6 and lut_hi[0xB] = 0x10 in the
default_or_url tables. It also corrects the Visual Studio spelling of the base64_url lut_hi, which had
0x6 where the other spelling has 0x4.

Our change of lut_lo[0xB], the comments, the lower bound of the walk back and the TestWTF test go.
The arm64 base64 section of the file is now byte for byte v9.0.0's arm_base64.cpp with 23556f1 applied.

* Source/WTF/wtf/simdutf/simdutf_impl.cpp.h:
(simdutf::arm64::to_base64_mask):
(simdutf::arm64::compress_decode_base64):
(simdutf::haswell::base64::compress_decode_base64):
(simdutf::westmere::base64::compress_decode_base64):
* Tools/TestWebKitAPI/Tests/WTF/Base64.cpp:
@dylan-conway
dylan-conway merged commit fe1e12e into main Oct 28, 2026
80 checks passed

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review found no issues

No high-confidence issues detected in this change.

robobun added a commit that referenced this pull request Oct 29, 2026
main is at 8c6c963: #919 (simdutf base64), #936 (ICU 79.1) and #937 (the
address space ballast is removed).

Two files conflict, CLAUDE.md and JSTests/BUN-TEST-DIFFERENCES.md, in the
count of upstream tests that the fork changes. The base says 124. This
branch adds 2 (the Proxy revoke function, the RegExp legacy properties) and
#936 adds 3 (the three Intl tests with CLDR 49's text), so it is 129.

Three more files changed on both sides and merged by themselves: Dockerfile,
heap/Heap.cpp and heap/Heap.h. No .ir test of the compiler changes in this
range, and the list of numbered engine functions is the same.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants