From 3e3745fb7fcabd79d8950b90801327309d079b50 Mon Sep 17 00:00:00 2001 From: Christophe Grenier Date: Sat, 9 Aug 2014 09:43:32 +0200 Subject: [PATCH] PhotoRec: stricter check for .dmp --- src/file_dmp.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/file_dmp.c b/src/file_dmp.c index 01cfd9c6..0532e9cc 100644 --- a/src/file_dmp.c +++ b/src/file_dmp.c @@ -31,7 +31,6 @@ #include "filegen.h" static void register_header_check_dmp(file_stat_t *file_stat); -static int header_check_dmp(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_dmp= { .extension="dmp", @@ -43,23 +42,21 @@ const file_hint_t file_hint_dmp= { .register_header_check=®ister_header_check_dmp }; -static const unsigned char dmp_header[11]= { - 0x03, 0x00, 0x01, 'E', 'X', 'P', 'O', 'R', - 'T', ':', 'V' -}; +static int header_check_dmp(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) +{ + if(buffer[11] < '0' || buffer[11] > '9') + return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension=file_hint_dmp.extension; + return 1; +} static void register_header_check_dmp(file_stat_t *file_stat) { + static const unsigned char dmp_header[11]= { + 0x03, 0x00, 0x01, 'E', 'X', 'P', 'O', 'R', + 'T', ':', 'V' + }; register_header_check(0, dmp_header, sizeof(dmp_header), &header_check_dmp, file_stat); } -static int header_check_dmp(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) -{ - if(memcmp(&buffer[0], dmp_header, sizeof(dmp_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_dmp.extension; - return 1; - } - return 0; -}