From 0b47724ef582ae21cec8ca5e0047e00bb9a986fe Mon Sep 17 00:00:00 2001 From: Christophe Grenier Date: Sat, 26 Jul 2014 22:51:32 +0200 Subject: [PATCH] PhotoRec: stricter check for .wdp --- src/file_wdp.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/file_wdp.c b/src/file_wdp.c index 72c7728a..0ab5e921 100644 --- a/src/file_wdp.c +++ b/src/file_wdp.c @@ -30,6 +30,7 @@ #include "types.h" #include "filegen.h" #include "file_tiff.h" +#include "common.h" static void register_header_check_wdp(file_stat_t *file_stat); static int header_check_wdp(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); @@ -44,24 +45,20 @@ const file_hint_t file_hint_wdp= { .register_header_check=®ister_header_check_wdp }; -static const unsigned char wdp_header[4]= {'I', 'I', 0xbc, 0x01}; +static int header_check_wdp(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 TIFFHeader *header=(const TIFFHeader *)buffer; + if(le32(header->tiff_diroff) < sizeof(TIFFHeader)) + return 0; + reset_file_recovery(file_recovery_new); + file_recovery_new->extension="wdp"; + file_recovery_new->time=get_date_from_tiff_header((const TIFFHeader *)buffer, buffer_size); + file_recovery_new->file_check=&file_check_tiff; + return 1; +} static void register_header_check_wdp(file_stat_t *file_stat) { + static const unsigned char wdp_header[4]= {'I', 'I', 0xbc, 0x01}; register_header_check(0, wdp_header, sizeof(wdp_header), &header_check_wdp, file_stat); } - -static int header_check_wdp(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, wdp_header, sizeof(wdp_header))==0) - { - reset_file_recovery(file_recovery_new); - file_recovery_new->extension="wdp"; - file_recovery_new->time=get_date_from_tiff_header((const TIFFHeader *)buffer, buffer_size); - file_recovery_new->file_check=&file_check_tiff; - return 1; - } - return 0; -} - -