LibGfx/JPEG: Propagate errors when creating JPEGLoadingContext

This allows the JPEG fuzzer to make progress.
This commit is contained in:
Tim Ledbetter 2023-10-29 10:31:04 +00:00 committed by Jelle Raaijmakers
parent a42d849ec1
commit 9ed8c0b183
Notes: sideshowbarker 2024-07-17 00:23:42 +09:00
2 changed files with 6 additions and 5 deletions

View file

@ -1926,9 +1926,9 @@ static ErrorOr<void> decode_jpeg(JPEGLoadingContext& context)
return {};
}
JPEGImageDecoderPlugin::JPEGImageDecoderPlugin(NonnullOwnPtr<FixedMemoryStream> stream)
JPEGImageDecoderPlugin::JPEGImageDecoderPlugin(NonnullOwnPtr<JPEGLoadingContext> context)
: m_context(move(context))
{
m_context = JPEGLoadingContext::create(move(stream)).release_value_but_fixme_should_propagate_errors();
}
JPEGImageDecoderPlugin::~JPEGImageDecoderPlugin() = default;
@ -1949,7 +1949,8 @@ bool JPEGImageDecoderPlugin::sniff(ReadonlyBytes data)
ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> JPEGImageDecoderPlugin::create(ReadonlyBytes data)
{
auto stream = TRY(try_make<FixedMemoryStream>(data));
auto plugin = TRY(adopt_nonnull_own_or_enomem(new (nothrow) JPEGImageDecoderPlugin(move(stream))));
auto context = TRY(JPEGLoadingContext::create(move(stream)));
auto plugin = TRY(adopt_nonnull_own_or_enomem(new (nothrow) JPEGImageDecoderPlugin(move(context))));
TRY(decode_header(*plugin->m_context));
return plugin;
}

View file

@ -28,9 +28,9 @@ public:
virtual ErrorOr<Optional<ReadonlyBytes>> icc_data() override;
private:
JPEGImageDecoderPlugin(NonnullOwnPtr<FixedMemoryStream>);
JPEGImageDecoderPlugin(NonnullOwnPtr<JPEGLoadingContext>);
OwnPtr<JPEGLoadingContext> m_context;
NonnullOwnPtr<JPEGLoadingContext> m_context;
};
}