summaryrefslogtreecommitdiffstats
path: root/src/file_cab.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2014-07-21 21:03:29 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2014-07-21 21:03:29 +0200
commit405ebd52d029461c9c41b266efd815c1166c330a (patch)
tree3bea15df559ac768bd0d8f1377d79155cda830b0 /src/file_cab.c
parentbe4ab36b9c1ce20fbf9d2b980822dd9be408069b (diff)
PhotoRec; stricter check for .cab
Diffstat (limited to 'src/file_cab.c')
-rw-r--r--src/file_cab.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/file_cab.c b/src/file_cab.c
index 6283405..9d23ea4 100644
--- a/src/file_cab.c
+++ b/src/file_cab.c
@@ -32,7 +32,6 @@
#include "filegen.h"
static void register_header_check_cab(file_stat_t *file_stat);
-static int header_check_cab(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_cab= {
.extension="cab",
@@ -44,7 +43,6 @@ const file_hint_t file_hint_cab= {
.register_header_check=&register_header_check_cab
};
-static const unsigned char cab_header[4] = { 'M','S','C','F'};
struct cab_header {
uint32_t magic;
uint32_t hdr_checksum;
@@ -60,15 +58,10 @@ struct cab_header {
uint16_t number;
} __attribute__ ((__packed__));
-static void register_header_check_cab(file_stat_t *file_stat)
-{
- register_header_check(0, cab_header,sizeof(cab_header), &header_check_cab, file_stat);
-}
-
static int header_check_cab(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 struct cab_header *cab_hdr=(const struct cab_header*)buffer;
- if(memcmp(buffer,cab_header,sizeof(cab_header))==0 && le16(cab_hdr->cab_version)==0x0103)
+ if(le16(cab_hdr->cab_version)==0x0103 && le32(cab_hdr->filesize) >= sizeof(struct cab_header))
{
reset_file_recovery(file_recovery_new);
file_recovery_new->extension=file_hint_cab.extension;
@@ -79,3 +72,9 @@ static int header_check_cab(const unsigned char *buffer, const unsigned int buff
}
return 0;
}
+
+static void register_header_check_cab(file_stat_t *file_stat)
+{
+ static const unsigned char cab_header[4] = { 'M','S','C','F'};
+ register_header_check(0, cab_header,sizeof(cab_header), &header_check_cab, file_stat);
+}