summaryrefslogtreecommitdiffstats
path: root/src/file_djv.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2014-08-09 09:42:42 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2014-08-09 09:42:42 +0200
commit7702cfd964c5a48489df65b3723a477432055df1 (patch)
tree1c9da04ba8ec7bd11bda36ed31b3e929f153edc1 /src/file_djv.c
parenta84642bcdeb2c2fe112b932985b3d74dc84d8197 (diff)
PhotoRec: stricter check for .djv
Diffstat (limited to 'src/file_djv.c')
-rw-r--r--src/file_djv.c36
1 files changed, 21 insertions, 15 deletions
diff --git a/src/file_djv.c b/src/file_djv.c
index 107f63c..bde84ec 100644
--- a/src/file_djv.c
+++ b/src/file_djv.c
@@ -29,9 +29,9 @@
#include <stdio.h>
#include "types.h"
#include "filegen.h"
+#include "common.h"
static void register_header_check_djv(file_stat_t *file_stat);
-static int header_check_djv(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new);
const file_hint_t file_hint_djv= {
.extension="djv",
@@ -43,23 +43,29 @@ const file_hint_t file_hint_djv= {
.register_header_check=&register_header_check_djv
};
-static const unsigned char djv_header[8]= { 'A','T','&','T','F','O','R','M'};
+struct djv_header
+{
+ uint32_t magic;
+ uint32_t type;
+ uint32_t size;
+} __attribute__ ((__packed__));
-static void register_header_check_djv(file_stat_t *file_stat)
+static int header_check_djv(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
{
- register_header_check(0, djv_header,sizeof(djv_header), &header_check_djv, file_stat);
+ const struct djv_header *hdr=(const struct djv_header *)buffer;
+ const uint64_t size=be32(hdr->size);
+ if(size==0 || size +12 > file_hint_djv.max_filesize)
+ return 0;
+ reset_file_recovery(file_recovery_new);
+ file_recovery_new->extension=file_hint_djv.extension;
+ file_recovery_new->calculated_file_size=size+12;
+ file_recovery_new->data_check=&data_check_size;
+ file_recovery_new->file_check=&file_check_size;
+ return 1;
}
-static int header_check_djv(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
+static void register_header_check_djv(file_stat_t *file_stat)
{
- if(memcmp(buffer,djv_header,sizeof(djv_header))==0)
- {
- reset_file_recovery(file_recovery_new);
- file_recovery_new->extension=file_hint_djv.extension;
- file_recovery_new->calculated_file_size=((uint64_t)buffer[8]<<24)+((uint64_t)buffer[8+1]<<16)+((uint64_t)buffer[8+2]<<8)+(uint64_t)buffer[8+3]+12;
- file_recovery_new->data_check=&data_check_size;
- file_recovery_new->file_check=&file_check_size;
- return 1;
- }
- return 0;
+ static const unsigned char djv_header[8]= { 'A','T','&','T','F','O','R','M'};
+ register_header_check(0, djv_header,sizeof(djv_header), &header_check_djv, file_stat);
}