1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:28:12 +00:00

LibIMAP: Propagate OOM errors from decode_quoted_printable()

This commit is contained in:
Linus Groh 2023-03-09 14:47:45 +00:00
parent 7d412983a8
commit f068ddb79f
5 changed files with 12 additions and 12 deletions

View file

@ -11,6 +11,6 @@
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size) extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
{ {
auto quoted_printable_string = StringView(static_cast<unsigned char const*>(data), 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; return 0;
} }

View file

@ -11,12 +11,12 @@
TEST_CASE(test_decode) TEST_CASE(test_decode)
{ {
auto decode_equal = [](StringView input, StringView expected) { 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()); EXPECT(decoded.bytes() == expected.bytes());
}; };
auto decode_equal_byte_buffer = [](StringView input, StringView expected) { 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()); EXPECT(decoded.bytes() == expected.bytes());
}; };
@ -44,6 +44,6 @@ TEST_CASE(test_decode)
illegal_character_builder.append(byte); 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()); EXPECT(illegal_character_decode.is_empty());
} }

View file

@ -500,7 +500,7 @@ void MailWidget::selected_email_to_load()
if (!decoded_base64.is_error()) if (!decoded_base64.is_error())
decoded_data = decoded_base64.release_value(); decoded_data = decoded_base64.release_value();
} else if (selected_alternative_encoding.equals_ignoring_case("quoted-printable"sv)) { } 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 { } else {
dbgln("Mail: Unimplemented decoder for encoding: {}", selected_alternative_encoding); 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); GUI::MessageBox::show(window(), DeprecatedString::formatted("The e-mail encoding '{}' is currently unsupported.", selected_alternative_encoding), "Unsupported"sv, GUI::MessageBox::Type::Information);

View file

@ -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 // 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); GenericLexer lexer(input);
StringBuilder output; StringBuilder output;
@ -50,7 +50,7 @@ ByteBuffer decode_quoted_printable(StringView input)
if (is_ascii_hex_digit(second_escape_character)) { 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); 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 { } else {
TODO(); 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. // Invalid escape sequence. RFC 2045 says a reasonable solution is just to append '=' followed by the character.
output.append('='); TRY(output.try_append('='));
output.append(first_escape_character); TRY(output.try_append(first_escape_character));
} }
} else { } else {
output.append(potential_character); TRY(output.try_append(potential_character));
} }
} }
return output.to_byte_buffer(); return output.try_to_byte_buffer();
} }
} }

View file

@ -10,6 +10,6 @@
namespace IMAP { namespace IMAP {
ByteBuffer decode_quoted_printable(StringView); ErrorOr<ByteBuffer> decode_quoted_printable(StringView);
} }