Skip to content

Conversation

@syg
Copy link
Contributor

@syg syg commented Jul 12, 2025

c5b50b5

[JSC] Fix Uint8Array fromBase64 and setFromBase64 for invalid 1-chunk input
https://bugs.webkit.org/show_bug.cgi?id=295578
rdar://155346981

Reviewed by Yusuke Suzuki.

This PR updates simdutf to 7.3.3, fixes handling of invalid 1-chunk input in
base64 decoding, and removes the slow fallback.

First, base64 input is changed to unconditionally decode even when the expected
decoded binary size is 0. Previously, there was a fast path in fromBase64 input
to an empty Uint8Array when the expected decoded binary size is 0. This is
incorrect when the input contains a single invalid chunk, as it skips decoding
entirely when it should attempt to and report the error.

Second, use simdutf to decode base64 for all values of lastChunkHandling.
Previously, simdutf was only used for 'loose', and a slow fallback was used for
'strict' and 'stop-before-partial'. Now simdutf has support for all 3, so use
it and remove the fallback.

Note that simdutf currently has a bug for the read count when lastChunkHandling
is 'stop-before-partial', which this patch works around.

Canonical link: https://commits.webkit.org/297335@main

33e2abc

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
❌ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win
✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 ⏳ 🧪 win-tests
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
✅ 🧪 ios-wk2-wpt ✅ 🧪 mac-wk1 ✅ 🛠 wpe-cairo
✅ 🛠 🧪 jsc ✅ 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk
✅ 🛠 🧪 jsc-arm64 ✅ 🛠 vision ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 vision-sim ✅ 🧪 mac-wk2-stress ✅ 🧪 api-gtk
✅ 🧪 vision-wk2 ✅ 🧪 mac-intel-wk2 🛠 playstation
✅ 🛠 🧪 unsafe-merge ✅ 🛠 tv ✅ 🛠 mac-safer-cpp ✅ 🛠 jsc-armv7
✅ 🛠 tv-sim ❌ 🧪 jsc-armv7-tests
✅ 🛠 watch
✅ 🛠 watch-sim

@syg syg requested a review from a team as a code owner July 12, 2025 01:27
@syg syg self-assigned this Jul 12, 2025
@syg syg added the JavaScriptCore For bugs in JavaScriptCore, the JS engine used by WebKit, other than kxmlcore issues. label Jul 12, 2025
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Jul 12, 2025
@syg syg removed the merging-blocked Applied to prevent a change from being merged label Jul 12, 2025
@syg syg force-pushed the dev/base64-reject-partial branch from 8614a8a to 6cb6e91 Compare July 12, 2025 01:40
@lemire
Copy link

lemire commented Jul 12, 2025

This should get fixed in the coming days upstream. @syg provided a PR at simdutf/simdutf#822

@lemire lemire mentioned this pull request Jul 12, 2025
@lemire
Copy link

lemire commented Jul 12, 2025

Please see simdutf/simdutf#823

@syg
Copy link
Contributor Author

syg commented Jul 13, 2025

This should get fixed in the coming days upstream. @syg provided a PR at simdutf/simdutf#822

To clarify I did not provide a fix, just imported the test262 test that shows the failure.

@syg syg force-pushed the dev/base64-reject-partial branch from 6cb6e91 to aeb3e7c Compare July 13, 2025 23:40
@syg syg force-pushed the dev/base64-reject-partial branch from aeb3e7c to 372b19a Compare July 14, 2025 03:58
@syg syg force-pushed the dev/base64-reject-partial branch from 372b19a to 33e2abc Compare July 14, 2025 04:09
static inline size_t fixSIMDUTFStopBeforePartialReadLength(std::span<const CharacterType> span, size_t readLengthFromSIMDUTF)
{
// Work around simdutf bug for stop-before-partial read length.
// FIXME: Remove once fixed in simdutf.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Constellation I chose to work around simdutf's non-compliant behavior for the read length instead of keeping the entire slow path. WDYT?

@Constellation Constellation added the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Jul 14, 2025
@webkit-commit-queue webkit-commit-queue force-pushed the dev/base64-reject-partial branch from 33e2abc to 5353d81 Compare July 14, 2025 15:14
… input

https://bugs.webkit.org/show_bug.cgi?id=295578
rdar://155346981

Reviewed by Yusuke Suzuki.

This PR updates simdutf to 7.3.3, fixes handling of invalid 1-chunk input in
base64 decoding, and removes the slow fallback.

First, base64 input is changed to unconditionally decode even when the expected
decoded binary size is 0. Previously, there was a fast path in fromBase64 input
to an empty Uint8Array when the expected decoded binary size is 0. This is
incorrect when the input contains a single invalid chunk, as it skips decoding
entirely when it should attempt to and report the error.

Second, use simdutf to decode base64 for all values of lastChunkHandling.
Previously, simdutf was only used for 'loose', and a slow fallback was used for
'strict' and 'stop-before-partial'. Now simdutf has support for all 3, so use
it and remove the fallback.

Note that simdutf currently has a bug for the read count when lastChunkHandling
is 'stop-before-partial', which this patch works around.

Canonical link: https://commits.webkit.org/297335@main
@webkit-commit-queue webkit-commit-queue force-pushed the dev/base64-reject-partial branch from 5353d81 to c5b50b5 Compare July 14, 2025 15:15
@webkit-commit-queue
Copy link
Collaborator

Committed 297335@main (c5b50b5): https://commits.webkit.org/297335@main

Reviewed commits have been landed. Closing PR #47926 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit c5b50b5 into WebKit:main Jul 14, 2025
@webkit-commit-queue webkit-commit-queue removed the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Jul 14, 2025
@lemire
Copy link

lemire commented Jul 14, 2025

@syg

To further clarify... yes, you 'only' provided the test. But this is obviously helpful as the issue was immediately reproducible.

@syg syg deleted the dev/base64-reject-partial branch July 18, 2025 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

JavaScriptCore For bugs in JavaScriptCore, the JS engine used by WebKit, other than kxmlcore issues.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants