mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-25 17:25:08 +02:00
AK: Don't convert encode_base64_impl() input to StringView
Since e47cdc6b, converting `ReadonlyBytes` to a `StringView` will crash
if the `ReadonlyBytes` given us empty. This caused a crash when calling
`btoa("")`, which called encode_base64() with an empty `ReadonlyBytes`.
We now don't convert the input from `ReadonlyBytes` to
`StringView`, which avoids this problem.
This commit is contained in:
committed by
Tim Ledbetter
parent
bd5424f435
commit
39585b1a00
Notes:
github-actions[bot]
2026-03-31 17:15:43 +00:00
Author: https://github.com/tcl3 Commit: https://github.com/LadybirdBrowser/ladybird/commit/39585b1a00f Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8710 Reviewed-by: https://github.com/gmta ✅
@@ -80,18 +80,18 @@ static ErrorOr<ByteBuffer> decode_base64_impl(StringView input, LastChunkHandlin
|
||||
return output;
|
||||
}
|
||||
|
||||
static ErrorOr<String> encode_base64_impl(StringView input, simdutf::base64_options options)
|
||||
static ErrorOr<String> encode_base64_impl(ReadonlyBytes input, simdutf::base64_options options)
|
||||
{
|
||||
if (input.is_empty())
|
||||
return String {};
|
||||
|
||||
u8* buffer = nullptr;
|
||||
auto output = TRY(AK::Detail::StringData::create_uninitialized(
|
||||
simdutf::base64_length_from_binary(input.length(), options), buffer));
|
||||
simdutf::base64_length_from_binary(input.size(), options), buffer));
|
||||
|
||||
simdutf::binary_to_base64(
|
||||
input.characters_without_null_termination(),
|
||||
input.length(),
|
||||
reinterpret_cast<char const*>(input.data()),
|
||||
input.size(),
|
||||
reinterpret_cast<char*>(buffer),
|
||||
options);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user