mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-24 08:59:50 +00:00
LibWeb+LibXML: Make Listener::set_source(ByteString) fallible
Some checks are pending
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
Some checks are pending
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
`set_source` takes a ByteString but the implementation might require a specific encoding. Make it fallible so that we don't need to crash in the case of invalid UTF-8 or similar. The test includes a sequence of invalid UTF-8 bytes that crash the browser without this change.
This commit is contained in:
parent
2397ae4af5
commit
b9554038ff
Notes:
github-actions[bot]
2025-10-02 00:27:16 +00:00
Author: https://github.com/rmg-x
Commit: b9554038ff
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6353
Reviewed-by: https://github.com/alimpfard ✅
Reviewed-by: https://github.com/trflynn89
7 changed files with 25 additions and 5 deletions
|
|
@ -62,9 +62,10 @@ XMLDocumentBuilder::XMLDocumentBuilder(DOM::Document& document, XMLScriptingSupp
|
|||
m_namespace_stack.append({ {}, 1 });
|
||||
}
|
||||
|
||||
void XMLDocumentBuilder::set_source(ByteString source)
|
||||
ErrorOr<void> XMLDocumentBuilder::set_source(ByteString source)
|
||||
{
|
||||
m_document->set_source(MUST(String::from_byte_string(source)));
|
||||
m_document->set_source(TRY(String::from_byte_string(source)));
|
||||
return {};
|
||||
}
|
||||
|
||||
void XMLDocumentBuilder::set_doctype(XML::Doctype doctype)
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ public:
|
|||
bool has_error() const { return m_has_error; }
|
||||
|
||||
private:
|
||||
virtual void set_source(ByteString) override;
|
||||
virtual ErrorOr<void> set_source(ByteString) override;
|
||||
virtual void set_doctype(XML::Doctype) override;
|
||||
virtual void element_start(XML::Name const& name, OrderedHashMap<XML::Name, ByteString> const& attributes) override;
|
||||
virtual void element_end(XML::Name const& name) override;
|
||||
|
|
|
|||
|
|
@ -199,7 +199,12 @@ ErrorOr<void, ParseError> Parser::parse_with_listener(Listener& listener)
|
|||
{
|
||||
m_listener = &listener;
|
||||
ScopeGuard unset_listener { [this] { m_listener = nullptr; } };
|
||||
m_listener->set_source(m_source);
|
||||
|
||||
if (auto const maybe_source_error = m_listener->set_source(m_source); maybe_source_error.is_error()) {
|
||||
auto const error_message = maybe_source_error.error().string_literal();
|
||||
return parse_error(m_lexer.current_position(), Expectation { error_message });
|
||||
}
|
||||
|
||||
m_listener->document_start();
|
||||
auto result = parse_internal();
|
||||
if (result.is_error())
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ struct ParseError {
|
|||
struct Listener {
|
||||
virtual ~Listener() { }
|
||||
|
||||
virtual void set_source(ByteString) { }
|
||||
virtual ErrorOr<void> set_source(ByteString) { return {}; }
|
||||
virtual void set_doctype(XML::Doctype) { }
|
||||
virtual void document_start() { }
|
||||
virtual void document_end() { }
|
||||
|
|
|
|||
1
Tests/LibWeb/Text/data/invalid_utf8_corrupt.svg
Normal file
1
Tests/LibWeb/Text/data/invalid_utf8_corrupt.svg
Normal file
|
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100">À¯õ</svg>
|
||||
|
After Width: | Height: | Size: 74 B |
1
Tests/LibWeb/Text/expected/corrupt-svg-favicon.txt
Normal file
1
Tests/LibWeb/Text/expected/corrupt-svg-favicon.txt
Normal file
|
|
@ -0,0 +1 @@
|
|||
PASS (didn't crash)
|
||||
12
Tests/LibWeb/Text/input/corrupt-svg-favicon.html
Normal file
12
Tests/LibWeb/Text/input/corrupt-svg-favicon.html
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<link rel="icon" href="../data/invalid_utf8_corrupt.svg" type="image/svg+xml">
|
||||
</head>
|
||||
<script src="include.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
println("PASS (didn't crash)")
|
||||
});
|
||||
</script>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue