From 7988bea96aac46aa1e3b0ce814aeb96a39634570 Mon Sep 17 00:00:00 2001 From: Feng Yu Date: Fri, 6 Dec 2024 09:35:02 -0800 Subject: [PATCH] LibWeb: Fix crash in Headers::get when handling values containing non-ASCII Latin1 characters headers list is ISO-8859-1 encoded using `Infra::isomorphic_encode`, so we should use decode them using `Infra::isomorphic_decode` before return. --- Libraries/LibWeb/Fetch/Headers.cpp | 3 ++- .../expected/Fetch/fetch-headers-get-nonascii.txt | 2 ++ .../input/Fetch/fetch-headers-get-nonascii.html | 13 +++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Text/expected/Fetch/fetch-headers-get-nonascii.txt create mode 100644 Tests/LibWeb/Text/input/Fetch/fetch-headers-get-nonascii.html diff --git a/Libraries/LibWeb/Fetch/Headers.cpp b/Libraries/LibWeb/Fetch/Headers.cpp index 1d4dbf31a7ecf..a3121e147603f 100644 --- a/Libraries/LibWeb/Fetch/Headers.cpp +++ b/Libraries/LibWeb/Fetch/Headers.cpp @@ -9,6 +9,7 @@ #include #include #include +#include namespace Web::Fetch { @@ -106,7 +107,7 @@ WebIDL::ExceptionOr> Headers::get(String const& name_string) // 2. Return the result of getting name from this’s header list. auto byte_buffer = m_header_list->get(name); - return byte_buffer.has_value() ? MUST(String::from_utf8(*byte_buffer)) : Optional {}; + return byte_buffer.has_value() ? Infra::isomorphic_decode(*byte_buffer) : Optional {}; } // https://fetch.spec.whatwg.org/#dom-headers-getsetcookie diff --git a/Tests/LibWeb/Text/expected/Fetch/fetch-headers-get-nonascii.txt b/Tests/LibWeb/Text/expected/Fetch/fetch-headers-get-nonascii.txt new file mode 100644 index 0000000000000..1927c53d4f0aa --- /dev/null +++ b/Tests/LibWeb/Text/expected/Fetch/fetch-headers-get-nonascii.txt @@ -0,0 +1,2 @@ +before-æøå-after +before-ß-after diff --git a/Tests/LibWeb/Text/input/Fetch/fetch-headers-get-nonascii.html b/Tests/LibWeb/Text/input/Fetch/fetch-headers-get-nonascii.html new file mode 100644 index 0000000000000..73e1f33da5d53 --- /dev/null +++ b/Tests/LibWeb/Text/input/Fetch/fetch-headers-get-nonascii.html @@ -0,0 +1,13 @@ + + +