Skip to content

Commit

Permalink
LibGfx/ILBM: Add validation for header fields
Browse files Browse the repository at this point in the history
We now exit early if a header field is set to a value that we don't
currently support.
  • Loading branch information
tcl3 authored and awesomekling committed Nov 8, 2023
1 parent bed7b33 commit 61eb754
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Userland/Libraries/LibGfx/ImageFormats/ILBMLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ struct Chunk {

enum class CompressionType : u8 {
None = 0,
ByteRun = 1
ByteRun = 1,
__Count
};

enum class MaskType : u8 {
None = 0,
HasMask = 1,
HasTransparentColor = 2,
HasLasso = 3
HasLasso = 3,
__Count
};

enum class ViewportMode : u32 {
Expand Down Expand Up @@ -329,6 +331,16 @@ static ErrorOr<void> decode_bmhd_chunk(ILBMLoadingContext& context)
return Error::from_string_literal("IFFImageDecoderPlugin: Not enough data for header chunk");

context.bm_header = *bit_cast<BMHDHeader const*>(first_chunk.data.data());

if (context.bm_header.planes > 8)
return Error::from_string_literal("IFFImageDecoderPlugin: Deep ILBMs are not currently supported");

if (context.bm_header.mask >= MaskType::__Count)
return Error::from_string_literal("IFFImageDecoderPlugin: Unsupported mask type");

if (context.bm_header.compression >= CompressionType::__Count)
return Error::from_string_literal("IFFImageDecoderPlugin: Unsupported compression type");

context.pitch = ceil_div((u16)context.bm_header.width, (u16)16) * 2;

context.state = ILBMLoadingContext::State::HeaderDecoded;
Expand Down

0 comments on commit 61eb754

Please sign in to comment.