mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:47:37 +00:00
LibGfx/PortableFormat: Propagate errors from decode()
This commit is contained in:
parent
7ec310384a
commit
fd04b2dc9b
2 changed files with 20 additions and 34 deletions
|
@ -184,52 +184,35 @@ static void set_pixels(TContext& context, Vector<Gfx::Color> const& color_data)
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename TContext>
|
template<typename TContext>
|
||||||
static bool decode(TContext& context)
|
static ErrorOr<void> decode(TContext& context)
|
||||||
{
|
{
|
||||||
if (context.state >= TContext::State::Decoded)
|
if (context.state >= TContext::State::Decoded)
|
||||||
return true;
|
return {};
|
||||||
|
|
||||||
auto error_guard = ArmedScopeGuard([&] {
|
TRY(read_magic_number(context));
|
||||||
context.state = TContext::State::Error;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (read_magic_number(context).is_error())
|
TRY(read_whitespace(context));
|
||||||
return false;
|
|
||||||
|
|
||||||
if (read_whitespace(context).is_error())
|
TRY(read_width(context));
|
||||||
return false;
|
TRY(read_whitespace(context));
|
||||||
|
TRY(read_height(context));
|
||||||
if (read_width(context).is_error())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (read_whitespace(context).is_error())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (read_height(context).is_error())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (context.width > maximum_width_for_decoded_images || context.height > maximum_height_for_decoded_images) {
|
if (context.width > maximum_width_for_decoded_images || context.height > maximum_height_for_decoded_images) {
|
||||||
dbgln("This portable network image is too large for comfort: {}x{}", context.width, context.height);
|
dbgln("This portable network image is too large for comfort: {}x{}", context.width, context.height);
|
||||||
return false;
|
return Error::from_string_literal("This portable network image is too large.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (read_whitespace(context).is_error())
|
TRY(read_whitespace(context));
|
||||||
return false;
|
|
||||||
|
|
||||||
if constexpr (requires { context.format_details.max_val; }) {
|
if constexpr (requires { context.format_details.max_val; }) {
|
||||||
if (read_max_val(context).is_error())
|
TRY(read_max_val(context));
|
||||||
return false;
|
TRY(read_whitespace(context));
|
||||||
|
|
||||||
if (read_whitespace(context).is_error())
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (read_image_data(context).is_error())
|
TRY(read_image_data(context));
|
||||||
return false;
|
|
||||||
|
|
||||||
error_guard.disarm();
|
|
||||||
context.state = TContext::State::Decoded;
|
context.state = TContext::State::Decoded;
|
||||||
return true;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,9 +93,11 @@ IntSize PortableImageDecoderPlugin<TContext>::size()
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
if (m_context->state < TContext::State::Decoded) {
|
if (m_context->state < TContext::State::Decoded) {
|
||||||
bool success = decode(*m_context);
|
if (decode(*m_context).is_error()) {
|
||||||
if (!success)
|
m_context->state = TContext::State::Error;
|
||||||
|
// FIXME: We should propagate errors
|
||||||
return {};
|
return {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return { m_context->width, m_context->height };
|
return { m_context->width, m_context->height };
|
||||||
|
@ -168,9 +170,10 @@ ErrorOr<ImageFrameDescriptor> PortableImageDecoderPlugin<TContext>::frame(size_t
|
||||||
return Error::from_string_literal("PortableImageDecoderPlugin: Decoding failed");
|
return Error::from_string_literal("PortableImageDecoderPlugin: Decoding failed");
|
||||||
|
|
||||||
if (m_context->state < TContext::State::Decoded) {
|
if (m_context->state < TContext::State::Decoded) {
|
||||||
bool success = decode(*m_context);
|
if (decode(*m_context).is_error()) {
|
||||||
if (!success)
|
m_context->state = TContext::State::Error;
|
||||||
return Error::from_string_literal("PortableImageDecoderPlugin: Decoding failed");
|
return Error::from_string_literal("PortableImageDecoderPlugin: Decoding failed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VERIFY(m_context->bitmap);
|
VERIFY(m_context->bitmap);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue