Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2018-01-16 12:00:13 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-01-16 12:02:32 +0300
commit03223a5e7d59d5f9d0057c677258380e04d86953 (patch)
treef95fff79ac07ab9e7209598ea1982de8d58c98f7 /source/blender/blenloader/intern
parente428ea3e0055dd95445694a72ff5c6b491a46ec7 (diff)
readfile: ensure blend header follows the spec
Diffstat (limited to 'source/blender/blenloader/intern')
-rw-r--r--source/blender/blenloader/intern/readfile.c60
1 files changed, 32 insertions, 28 deletions
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 <math.h> // for fabs
#include <stdarg.h> /* for va_start/end */
#include <time.h> /* for gmtime */
+#include <ctype.h> /* 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);
}
}