bmp: Ensure that bf_offset + bf_size <= file size

This commit is contained in:
mintsuki 2021-09-25 02:02:21 +02:00
parent 5374e4e1f2
commit b7176d5cfa

View File

@ -40,7 +40,15 @@ int bmp_open_image(struct image *image, struct file_handle *file) {
return -1;
image->img = ext_mem_alloc(header.bf_size);
fread(file, image->img, header.bf_offset, header.bf_size);
uint32_t bf_size;
if (header.bf_offset + header.bf_size > file->size) {
bf_size = file->size - header.bf_offset;
} else {
bf_size = header.bf_size;
}
fread(file, image->img, header.bf_offset, bf_size);
image->x_size = header.bi_width;
image->y_size = header.bi_height;