mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
LibIMAP: Propagate OOM errors from decode_quoted_printable()
This commit is contained in:
parent
7d412983a8
commit
f068ddb79f
Notes:
sideshowbarker
2024-07-16 23:52:10 +09:00
5 changed files with 12 additions and 12 deletions
|
@ -11,6 +11,6 @@
|
|||
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
|
||||
{
|
||||
auto quoted_printable_string = StringView(static_cast<unsigned char const*>(data), size);
|
||||
IMAP::decode_quoted_printable(quoted_printable_string);
|
||||
(void)IMAP::decode_quoted_printable(quoted_printable_string);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -11,12 +11,12 @@
|
|||
TEST_CASE(test_decode)
|
||||
{
|
||||
auto decode_equal = [](StringView input, StringView expected) {
|
||||
auto decoded = IMAP::decode_quoted_printable(input);
|
||||
auto decoded = MUST(IMAP::decode_quoted_printable(input));
|
||||
EXPECT(decoded.bytes() == expected.bytes());
|
||||
};
|
||||
|
||||
auto decode_equal_byte_buffer = [](StringView input, StringView expected) {
|
||||
auto decoded = IMAP::decode_quoted_printable(input);
|
||||
auto decoded = MUST(IMAP::decode_quoted_printable(input));
|
||||
EXPECT(decoded.bytes() == expected.bytes());
|
||||
};
|
||||
|
||||
|
@ -44,6 +44,6 @@ TEST_CASE(test_decode)
|
|||
illegal_character_builder.append(byte);
|
||||
}
|
||||
|
||||
auto illegal_character_decode = IMAP::decode_quoted_printable(illegal_character_builder.to_deprecated_string());
|
||||
auto illegal_character_decode = MUST(IMAP::decode_quoted_printable(illegal_character_builder.to_deprecated_string()));
|
||||
EXPECT(illegal_character_decode.is_empty());
|
||||
}
|
||||
|
|
|
@ -500,7 +500,7 @@ void MailWidget::selected_email_to_load()
|
|||
if (!decoded_base64.is_error())
|
||||
decoded_data = decoded_base64.release_value();
|
||||
} else if (selected_alternative_encoding.equals_ignoring_case("quoted-printable"sv)) {
|
||||
decoded_data = IMAP::decode_quoted_printable(encoded_data);
|
||||
decoded_data = IMAP::decode_quoted_printable(encoded_data).release_value_but_fixme_should_propagate_errors();
|
||||
} else {
|
||||
dbgln("Mail: Unimplemented decoder for encoding: {}", selected_alternative_encoding);
|
||||
GUI::MessageBox::show(window(), DeprecatedString::formatted("The e-mail encoding '{}' is currently unsupported.", selected_alternative_encoding), "Unsupported"sv, GUI::MessageBox::Type::Information);
|
||||
|
|
|
@ -17,7 +17,7 @@ static constexpr bool is_illegal_character(char c)
|
|||
}
|
||||
|
||||
// RFC 2045 Section 6.7 "Quoted-Printable Content-Transfer-Encoding", https://datatracker.ietf.org/doc/html/rfc2045#section-6.7
|
||||
ByteBuffer decode_quoted_printable(StringView input)
|
||||
ErrorOr<ByteBuffer> decode_quoted_printable(StringView input)
|
||||
{
|
||||
GenericLexer lexer(input);
|
||||
StringBuilder output;
|
||||
|
@ -50,7 +50,7 @@ ByteBuffer decode_quoted_printable(StringView input)
|
|||
|
||||
if (is_ascii_hex_digit(second_escape_character)) {
|
||||
u8 actual_character = (parse_ascii_hex_digit(first_escape_character) << 4) | parse_ascii_hex_digit(second_escape_character);
|
||||
output.append(actual_character);
|
||||
TRY(output.try_append(actual_character));
|
||||
} else {
|
||||
TODO();
|
||||
}
|
||||
|
@ -72,15 +72,15 @@ ByteBuffer decode_quoted_printable(StringView input)
|
|||
}
|
||||
|
||||
// Invalid escape sequence. RFC 2045 says a reasonable solution is just to append '=' followed by the character.
|
||||
output.append('=');
|
||||
output.append(first_escape_character);
|
||||
TRY(output.try_append('='));
|
||||
TRY(output.try_append(first_escape_character));
|
||||
}
|
||||
} else {
|
||||
output.append(potential_character);
|
||||
TRY(output.try_append(potential_character));
|
||||
}
|
||||
}
|
||||
|
||||
return output.to_byte_buffer();
|
||||
return output.try_to_byte_buffer();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,6 +10,6 @@
|
|||
|
||||
namespace IMAP {
|
||||
|
||||
ByteBuffer decode_quoted_printable(StringView);
|
||||
ErrorOr<ByteBuffer> decode_quoted_printable(StringView);
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue