diff --git a/docs/changelog.md b/docs/changelog.md index 085a9b3..5144cc4 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -13,6 +13,7 @@ Note: releases are listed from latest to oldest. process to fail (the background is ignored instead if there are no available palette slots) - Added some warning flags for debug builds, and cleared some warnings that would be raised by them - Added and improved some safety checks that detect maliciously-crafted and other pathological files +- Added detection for empty GIF files (erroring out with `PLUM_ERR_NO_DATA` instead of `PLUM_ERR_INVALID_FILE_FORMAT`) - Some minor documentation updates and code cleanup ## Version 0.3 (10 January 2022) diff --git a/src/load.c b/src/load.c index 09d3617..26d1243 100644 --- a/src/load.c +++ b/src/load.c @@ -44,6 +44,10 @@ struct plum_image * plum_load_image_limited (const void * restrict buffer, size_ } void load_image_buffer_data (struct context * context, unsigned flags, size_t limit) { + if ((context -> size == 7) && (bytematch(context -> data, 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x3b) || + bytematch(context -> data, 0x47, 0x49, 0x46, 0x38, 0x37, 0x61, 0x3b))) + // empty GIF file + throw(context, PLUM_ERR_NO_DATA); if (context -> size < 8) throw(context, PLUM_ERR_INVALID_FILE_FORMAT); if (bytematch(context -> data, 0x42, 0x4d)) load_BMP_data(context, flags, limit);