Skip to content

arm64: fix base64 default_or_url tables accepting '[' - #1062

Merged
lemire merged 1 commit into
masterfrom
arm64-base64-default-or-url-bracket
Oct 27, 2026
Merged

lemire merged 1 commit into
masterfrom
arm64-base64-default-or-url-bracket

Conversation

@lemire

@lemire lemire commented Oct 27, 2026

Copy link
Copy Markdown
Member

On arm64, the base64 decoder took '[' (0x5B) for a base64 character with base64_default_or_url and base64_default_or_url_accept_garbage. In to_base64_mask, the default_or_url tables gave '+' and '_' the same bit, so '[' passed as well (lut_lo[0xB] & lut_hi[0xB] = 0xa2 & 0x12 = 0x02). The scalar table rejects it.

Consequences:

  • base64_default_or_url: '[' was decoded instead of reported as INVALID_BASE64_CHARACTER.
  • base64_default_or_url_accept_garbage: '[' was not skipped.

Fix: '_' now uses bit 0x10, which only X/Y/Z share in that row (lut_lo[0xF] = 0xb6, lut_hi[0xB] = 0x10).

Reported by Dylan Conway (@dylan-conway, Bun), who found the cause and provided a reproducer.

In to_base64_mask, the default_or_url tables gave '+' and '_' the same
bit, so '[' (lut_lo[0xB] & lut_hi[0xB] = 0xa2 & 0x12) was taken for a
base64 character. The scalar tables reject it. With
base64_default_or_url, '[' was decoded instead of reported as
INVALID_BASE64_CHARACTER; with base64_default_or_url_accept_garbage, it
was not skipped.

'_' now uses bit 0x10 (lut_lo[0xF] = 0xb6, lut_hi[0xB] = 0x10).

Reported-by: Dylan Conway <[email protected]>
@lemire
lemire merged commit 23556f1 into master Oct 27, 2026
97 checks passed
dylan-conway pushed a commit to oven-sh/WebKit that referenced this pull request Oct 28, 2026
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:
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.

1 participant