In KXL_ReadBitmapHeader(), there were a few places where execution would loop for a long time on a corrupt bitmap file, because hed->pals (the size of the hed->rgb color table) and hed->image_size were way too large, even larger than the remaining length of the file.
I've fixed the infinite loops by changing the function to bail out early if that happens. Also, I changed some exit() calls to instead simply clean up and return. Since hed->data is nulled near the beginning of ReadBitmapHeader, checking whether that's NULL is an easy way to tell if the function failed. Also, LoadBitmap can now return NULL.
TODO:
[x] Document that if ReadBitmapHeader() fails, hed->data will be NULL.
[x] Document that LoadBitmap() will now return NULL upon failure.
In KXL_ReadBitmapHeader(), there were a few places where execution would loop for a long time on a corrupt bitmap file, because
hed->pals
(the size of thehed->rgb
color table) andhed->image_size
were way too large, even larger than the remaining length of the file.I've fixed the infinite loops by changing the function to bail out early if that happens. Also, I changed some exit() calls to instead simply clean up and return. Since
hed->data
is nulled near the beginning of ReadBitmapHeader, checking whether that's NULL is an easy way to tell if the function failed. Also, LoadBitmap can now return NULL.TODO:
hed->data
will be NULL.