diff options
author | Campbell Barton <ideasman42@gmail.com> | 2020-11-11 08:14:06 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-11-11 08:14:06 +0300 |
commit | 2d60845786aeab099c61ffa42b7f72cccc68bff1 (patch) | |
tree | aa3f17a33f029f9a8de69b081d219ee506e71f8e /source/blender/imbuf/intern/dds | |
parent | 99f56b4c16323f96c0cbf54e392fb509fcac5bda (diff) |
Cleanup: pass header size to 'is_a' callbacks
No functional changes, prepare for fixing out-of-bounds access
when reading headers.
Diffstat (limited to 'source/blender/imbuf/intern/dds')
-rw-r--r-- | source/blender/imbuf/intern/dds/dds_api.cpp | 11 | ||||
-rw-r--r-- | source/blender/imbuf/intern/dds/dds_api.h | 3 |
2 files changed, 8 insertions, 6 deletions
diff --git a/source/blender/imbuf/intern/dds/dds_api.cpp b/source/blender/imbuf/intern/dds/dds_api.cpp index d8bcca7e1f5..78ce8b5ee9b 100644 --- a/source/blender/imbuf/intern/dds/dds_api.cpp +++ b/source/blender/imbuf/intern/dds/dds_api.cpp @@ -72,18 +72,19 @@ bool imb_save_dds(struct ImBuf *ibuf, const char *name, int /*flags*/) return true; } -int imb_is_a_dds(const unsigned char *mem) /* note: use at most first 32 bytes */ +/* note: use at most first 32 bytes */ +bool imb_is_a_dds(const unsigned char *mem, size_t UNUSED(size)) { /* heuristic check to see if mem contains a DDS file */ /* header.fourcc == FOURCC_DDS */ if ((mem[0] != 'D') || (mem[1] != 'D') || (mem[2] != 'S') || (mem[3] != ' ')) { - return 0; + return false; } /* header.size == 124 */ if ((mem[4] != 124) || mem[5] || mem[6] || mem[7]) { - return 0; + return false; } - return 1; + return true; } struct ImBuf *imb_load_dds(const unsigned char *mem, @@ -108,7 +109,7 @@ struct ImBuf *imb_load_dds(const unsigned char *mem, */ colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_BYTE); - if (!imb_is_a_dds(mem)) { + if (!imb_is_a_dds(mem, size)) { return nullptr; } diff --git a/source/blender/imbuf/intern/dds/dds_api.h b/source/blender/imbuf/intern/dds/dds_api.h index ca74cbeaa74..9020529f210 100644 --- a/source/blender/imbuf/intern/dds/dds_api.h +++ b/source/blender/imbuf/intern/dds/dds_api.h @@ -26,7 +26,8 @@ extern "C" { #endif -int imb_is_a_dds(const unsigned char *mem); /* use only first 32 bytes of mem */ +/* use only first 32 bytes of mem */ +bool imb_is_a_dds(const unsigned char *mem, const size_t size); bool imb_save_dds(struct ImBuf *ibuf, const char *name, int flags); struct ImBuf *imb_load_dds(const unsigned char *mem, size_t size, |