mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-13 21:12:26 +00:00
LibWasm: Validate that names are UTF-8
This commit is contained in:
parent
7560b640f3
commit
c86e89665b
Notes:
sideshowbarker
2024-07-17 03:30:41 +09:00
Author: https://github.com/dzfrias
Commit: c86e89665b
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/96
Reviewed-by: https://github.com/alimpfard ✅
2 changed files with 7 additions and 1 deletions
|
@ -79,7 +79,10 @@ static ParseResult<ByteString> parse_name(Stream& stream)
|
||||||
{
|
{
|
||||||
ScopeLogger<WASM_BINPARSER_DEBUG> logger;
|
ScopeLogger<WASM_BINPARSER_DEBUG> logger;
|
||||||
auto data = TRY(parse_vector<u8>(stream));
|
auto data = TRY(parse_vector<u8>(stream));
|
||||||
return ByteString::copy(data);
|
auto string = ByteString::copy(data);
|
||||||
|
if (!Utf8View(string).validate(Utf8View::AllowSurrogates::No))
|
||||||
|
return ParseError::InvalidUtf8;
|
||||||
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -1546,6 +1549,8 @@ ByteString parse_error_to_byte_string(ParseError error)
|
||||||
return "A parsed instruction immediate was invalid for the instruction it was used for";
|
return "A parsed instruction immediate was invalid for the instruction it was used for";
|
||||||
case ParseError::SectionSizeMismatch:
|
case ParseError::SectionSizeMismatch:
|
||||||
return "A parsed section did not fulfill its expected size";
|
return "A parsed section did not fulfill its expected size";
|
||||||
|
case ParseError::InvalidUtf8:
|
||||||
|
return "A parsed string was not valid UTF-8";
|
||||||
case ParseError::UnknownInstruction:
|
case ParseError::UnknownInstruction:
|
||||||
return "A parsed instruction was not known to this parser";
|
return "A parsed instruction was not known to this parser";
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,7 @@ enum class ParseError {
|
||||||
HugeAllocationRequested,
|
HugeAllocationRequested,
|
||||||
OutOfMemory,
|
OutOfMemory,
|
||||||
SectionSizeMismatch,
|
SectionSizeMismatch,
|
||||||
|
InvalidUtf8,
|
||||||
// FIXME: This should not exist!
|
// FIXME: This should not exist!
|
||||||
NotImplemented,
|
NotImplemented,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue