summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2014-07-26 22:41:49 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2014-07-26 22:41:49 +0200
commitc2af34417fa2c1ae42a07704de3a44e95fa5e3bc (patch)
treef3f288f983c9a95b2685bbf6a47470be106e8f5f
parent078e875764ec86b14d1e9d3ca475e6bf248a9bfd (diff)
PhotoRec: stricter check for .rw2
-rw-r--r--src/file_rw2.c31
1 files changed, 14 insertions, 17 deletions
diff --git a/src/file_rw2.c b/src/file_rw2.c
index 157a9ac..1a1ea1c 100644
--- a/src/file_rw2.c
+++ b/src/file_rw2.c
@@ -30,6 +30,7 @@
#include "types.h"
#include "filegen.h"
#include "file_tiff.h"
+#include "common.h"
static void register_header_check_rw2(file_stat_t *file_stat);
static int header_check_rw2(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,25 +45,21 @@ const file_hint_t file_hint_rw2= {
.register_header_check=&register_header_check_rw2
};
-static const unsigned char rw2_header_panasonic[4]= {'I','I','U','\0'};
-
-static void register_header_check_rw2(file_stat_t *file_stat)
-{
- register_header_check(0, rw2_header_panasonic, sizeof(rw2_header_panasonic), &header_check_rw2, file_stat);
-}
-
static int header_check_rw2(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;
/* Panasonic/Leica */
- if(memcmp(buffer, rw2_header_panasonic, sizeof(rw2_header_panasonic))==0)
- {
- reset_file_recovery(file_recovery_new);
- file_recovery_new->extension="rw2";
- 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;
+ reset_file_recovery(file_recovery_new);
+ file_recovery_new->extension="rw2";
+ file_recovery_new->time=get_date_from_tiff_header(header, buffer_size);
+ file_recovery_new->file_check=&file_check_tiff;
+ return 1;
}
-
+static void register_header_check_rw2(file_stat_t *file_stat)
+{
+ static const unsigned char rw2_header_panasonic[4]= {'I','I','U','\0'};
+ register_header_check(0, rw2_header_panasonic, sizeof(rw2_header_panasonic), &header_check_rw2, file_stat);
+}