mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
LibGfx/BMPLoader: Ensure data offset cannot point past EOF
This commit is contained in:
parent
9788576936
commit
a673062084
Notes:
sideshowbarker
2024-07-17 18:49:10 +09:00
Author: https://github.com/tcl3 Commit: https://github.com/SerenityOS/serenity/commit/a673062084 Pull-request: https://github.com/SerenityOS/serenity/pull/21416
1 changed files with 11 additions and 0 deletions
|
@ -518,6 +518,11 @@ static ErrorOr<void> decode_bmp_header(BMPLoadingContext& context)
|
|||
// Ignore reserved bytes
|
||||
streamer.drop_bytes(4);
|
||||
context.data_offset = streamer.read_u32();
|
||||
if (context.data_offset >= context.file_size) {
|
||||
dbgln_if(BMP_DEBUG, "BMP has invalid data offset: {}", context.data_offset);
|
||||
context.state = BMPLoadingContext::State::Error;
|
||||
return Error::from_string_literal("BMP has invalid data offset");
|
||||
}
|
||||
|
||||
if constexpr (BMP_DEBUG) {
|
||||
dbgln("BMP file size: {}", context.file_size);
|
||||
|
@ -923,6 +928,12 @@ static ErrorOr<void> decode_bmp_dib(BMPLoadingContext& context)
|
|||
}
|
||||
}
|
||||
|
||||
if (context.data_offset >= context.file_size) {
|
||||
dbgln_if(BMP_DEBUG, "BMP has invalid data offset: {}", context.data_offset);
|
||||
context.state = BMPLoadingContext::State::Error;
|
||||
return Error::from_string_literal("BMP has invalid data offset");
|
||||
}
|
||||
|
||||
context.state = BMPLoadingContext::State::DIBDecoded;
|
||||
|
||||
return {};
|
||||
|
|
Loading…
Reference in a new issue