diff --git a/Meta/Lagom/Fuzzers/FuzzQuotedPrintableParser.cpp b/Meta/Lagom/Fuzzers/FuzzQuotedPrintableParser.cpp index c1bf58c3720..c563d53bb2d 100644 --- a/Meta/Lagom/Fuzzers/FuzzQuotedPrintableParser.cpp +++ b/Meta/Lagom/Fuzzers/FuzzQuotedPrintableParser.cpp @@ -11,6 +11,6 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size) { auto quoted_printable_string = StringView(static_cast(data), size); - IMAP::decode_quoted_printable(quoted_printable_string); + (void)IMAP::decode_quoted_printable(quoted_printable_string); return 0; } diff --git a/Tests/LibIMAP/TestQuotedPrintable.cpp b/Tests/LibIMAP/TestQuotedPrintable.cpp index 13b2aa1e15f..16feb08e444 100644 --- a/Tests/LibIMAP/TestQuotedPrintable.cpp +++ b/Tests/LibIMAP/TestQuotedPrintable.cpp @@ -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()); } diff --git a/Userland/Applications/Mail/MailWidget.cpp b/Userland/Applications/Mail/MailWidget.cpp index 8d12c3a58d7..f0d1cf794b7 100644 --- a/Userland/Applications/Mail/MailWidget.cpp +++ b/Userland/Applications/Mail/MailWidget.cpp @@ -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); diff --git a/Userland/Libraries/LibIMAP/QuotedPrintable.cpp b/Userland/Libraries/LibIMAP/QuotedPrintable.cpp index 901a59f000c..31461c08ab4 100644 --- a/Userland/Libraries/LibIMAP/QuotedPrintable.cpp +++ b/Userland/Libraries/LibIMAP/QuotedPrintable.cpp @@ -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 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(); } } diff --git a/Userland/Libraries/LibIMAP/QuotedPrintable.h b/Userland/Libraries/LibIMAP/QuotedPrintable.h index ac6508decac..7b1867ffc76 100644 --- a/Userland/Libraries/LibIMAP/QuotedPrintable.h +++ b/Userland/Libraries/LibIMAP/QuotedPrintable.h @@ -10,6 +10,6 @@ namespace IMAP { -ByteBuffer decode_quoted_printable(StringView); +ErrorOr decode_quoted_printable(StringView); }