From 03223a5e7d59d5f9d0057c677258380e04d86953 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 16 Jan 2018 20:00:13 +1100 Subject: readfile: ensure blend header follows the spec --- source/blender/blenloader/intern/readfile.c | 60 +++++++++++++++-------------- 1 file changed, 32 insertions(+), 28 deletions(-) (limited to 'source/blender/blenloader/intern') diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 37e41fa8968..bc51f0fe96b 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -41,6 +41,7 @@ #include // for fabs #include /* for va_start/end */ #include /* for gmtime */ +#include /* for isdigit */ #include "BLI_utildefines.h" #ifndef WIN32 @@ -882,39 +883,42 @@ static void decode_blender_header(FileData *fd) { char header[SIZEOFBLENDERHEADER], num[4]; int readsize; - + /* read in the header data */ readsize = fd->read(fd, header, sizeof(header)); - - if (readsize == sizeof(header)) { - if (STREQLEN(header, "BLENDER", 7)) { - fd->flags |= FD_FLAGS_FILE_OK; - - /* what size are pointers in the file ? */ - if (header[7]=='_') { - fd->flags |= FD_FLAGS_FILE_POINTSIZE_IS_4; - if (sizeof(void *) != 4) { - fd->flags |= FD_FLAGS_POINTSIZE_DIFFERS; - } - } - else { - if (sizeof(void *) != 8) { - fd->flags |= FD_FLAGS_POINTSIZE_DIFFERS; - } + + if (readsize == sizeof(header) && + STREQLEN(header, "BLENDER", 7) && + ELEM(header[7], '_', '-') && + ELEM(header[8], 'v', 'V') && + (isdigit(header[9]) && isdigit(header[10]) && isdigit(header[11]))) + { + fd->flags |= FD_FLAGS_FILE_OK; + + /* what size are pointers in the file ? */ + if (header[7] == '_') { + fd->flags |= FD_FLAGS_FILE_POINTSIZE_IS_4; + if (sizeof(void *) != 4) { + fd->flags |= FD_FLAGS_POINTSIZE_DIFFERS; } - - /* is the file saved in a different endian - * than we need ? - */ - if (((header[8] == 'v') ? L_ENDIAN : B_ENDIAN) != ENDIAN_ORDER) { - fd->flags |= FD_FLAGS_SWITCH_ENDIAN; + } + else { + if (sizeof(void *) != 8) { + fd->flags |= FD_FLAGS_POINTSIZE_DIFFERS; } - - /* get the version number */ - memcpy(num, header + 9, 3); - num[3] = 0; - fd->fileversion = atoi(num); } + + /* is the file saved in a different endian + * than we need ? + */ + if (((header[8] == 'v') ? L_ENDIAN : B_ENDIAN) != ENDIAN_ORDER) { + fd->flags |= FD_FLAGS_SWITCH_ENDIAN; + } + + /* get the version number */ + memcpy(num, header + 9, 3); + num[3] = 0; + fd->fileversion = atoi(num); } } -- cgit v1.2.3