diff --git a/Tests/LibGfx/TestImageDecoder.cpp b/Tests/LibGfx/TestImageDecoder.cpp index 34ca809c03..8db8b059fb 100644 --- a/Tests/LibGfx/TestImageDecoder.cpp +++ b/Tests/LibGfx/TestImageDecoder.cpp @@ -557,7 +557,7 @@ TEST_CASE(test_ppm) TEST_CASE(test_targa_bottom_left) { auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tga/buggie-bottom-left-uncompressed.tga"sv))); - EXPECT(TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::validate_before_create(file->bytes()))); + EXPECT(Gfx::TGAImageDecoderPlugin::validate_before_create(file->bytes())); auto plugin_decoder = TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::create(file->bytes())); TRY_OR_FAIL(expect_single_frame(*plugin_decoder)); @@ -566,7 +566,7 @@ TEST_CASE(test_targa_bottom_left) TEST_CASE(test_targa_top_left) { auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tga/buggie-top-left-uncompressed.tga"sv))); - EXPECT(TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::validate_before_create(file->bytes()))); + EXPECT(Gfx::TGAImageDecoderPlugin::validate_before_create(file->bytes())); auto plugin_decoder = TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::create(file->bytes())); TRY_OR_FAIL(expect_single_frame(*plugin_decoder)); @@ -575,7 +575,7 @@ TEST_CASE(test_targa_top_left) TEST_CASE(test_targa_bottom_left_compressed) { auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tga/buggie-bottom-left-compressed.tga"sv))); - EXPECT(TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::validate_before_create(file->bytes()))); + EXPECT(Gfx::TGAImageDecoderPlugin::validate_before_create(file->bytes())); auto plugin_decoder = TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::create(file->bytes())); TRY_OR_FAIL(expect_single_frame(*plugin_decoder)); @@ -584,7 +584,7 @@ TEST_CASE(test_targa_bottom_left_compressed) TEST_CASE(test_targa_top_left_compressed) { auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tga/buggie-top-left-compressed.tga"sv))); - EXPECT(TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::validate_before_create(file->bytes()))); + EXPECT(Gfx::TGAImageDecoderPlugin::validate_before_create(file->bytes())); auto plugin_decoder = TRY_OR_FAIL(Gfx::TGAImageDecoderPlugin::create(file->bytes())); TRY_OR_FAIL(expect_single_frame(*plugin_decoder)); diff --git a/Userland/Libraries/LibGfx/ImageFormats/ImageDecoder.cpp b/Userland/Libraries/LibGfx/ImageFormats/ImageDecoder.cpp index 5f703f8d14..d9f069e77a 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/ImageDecoder.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/ImageDecoder.cpp @@ -64,7 +64,7 @@ static ErrorOr> probe_and_sniff_for_appropriate_plugi static OwnPtr probe_and_sniff_for_appropriate_plugin_with_known_mime_type(StringView mime_type, ReadonlyBytes bytes) { struct ImagePluginWithMIMETypeInitializer { - ErrorOr (*validate_before_create)(ReadonlyBytes) = nullptr; + bool (*validate_before_create)(ReadonlyBytes) = nullptr; ErrorOr> (*create)(ReadonlyBytes) = nullptr; StringView mime_type; }; @@ -76,7 +76,7 @@ static OwnPtr probe_and_sniff_for_appropriate_plugin_with_kn for (auto& plugin : s_initializers_with_mime_type) { if (plugin.mime_type != mime_type) continue; - auto validation_result = plugin.validate_before_create(bytes).release_value_but_fixme_should_propagate_errors(); + auto validation_result = plugin.validate_before_create(bytes); if (!validation_result) continue; auto plugin_decoder = plugin.create(bytes); diff --git a/Userland/Libraries/LibGfx/ImageFormats/TGALoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/TGALoader.cpp index 98b53655e7..a3427bf954 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/TGALoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/TGALoader.cpp @@ -91,11 +91,13 @@ ErrorOr TGAImageDecoderPlugin::decode_tga_header() return {}; } -ErrorOr TGAImageDecoderPlugin::validate_before_create(ReadonlyBytes data) +bool TGAImageDecoderPlugin::validate_before_create(ReadonlyBytes data) { FixedMemoryStream stream { data }; - auto header = TRY(stream.read_value()); - return !ensure_header_validity(header, data.size()).is_error(); + auto header_or_err = stream.read_value(); + if (header_or_err.is_error()) + return false; + return !ensure_header_validity(header_or_err.release_value(), data.size()).is_error(); } ErrorOr> TGAImageDecoderPlugin::create(ReadonlyBytes data) diff --git a/Userland/Libraries/LibGfx/ImageFormats/TGALoader.h b/Userland/Libraries/LibGfx/ImageFormats/TGALoader.h index ddcb25d8ad..ad0899cf15 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/TGALoader.h +++ b/Userland/Libraries/LibGfx/ImageFormats/TGALoader.h @@ -14,7 +14,7 @@ struct TGALoadingContext; class TGAImageDecoderPlugin final : public ImageDecoderPlugin { public: - static ErrorOr validate_before_create(ReadonlyBytes); + static bool validate_before_create(ReadonlyBytes); static ErrorOr> create(ReadonlyBytes); virtual ~TGAImageDecoderPlugin() override;