LibGfx/BMPLoader: Ensure data offset cannot point past EOF

This commit is contained in:
Tim Ledbetter 2023-10-11 18:12:26 +01:00 committed by Tim Flynn
parent 9788576936
commit a673062084
Notes: sideshowbarker 2024-07-17 18:49:10 +09:00

View file

@ -518,6 +518,11 @@ static ErrorOr<void> decode_bmp_header(BMPLoadingContext& context)
// Ignore reserved bytes // Ignore reserved bytes
streamer.drop_bytes(4); streamer.drop_bytes(4);
context.data_offset = streamer.read_u32(); 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) { if constexpr (BMP_DEBUG) {
dbgln("BMP file size: {}", context.file_size); 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; context.state = BMPLoadingContext::State::DIBDecoded;
return {}; return {};