summaryrefslogtreecommitdiffstats
path: root/src/file_asf.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2013-03-23 14:47:06 +0100
committerChristophe Grenier <grenier@cgsecurity.org>2013-03-23 14:47:06 +0100
commit0f70bee69a6ce66c2b2798d09235439924906a0b (patch)
tree5033f516a003717897e27121b78120a05709b678 /src/file_asf.c
parent7129c28c12bdb416725a906c425c1ec2d43df6a9 (diff)
PhotoRec: stricter check for .asf detection
Diffstat (limited to 'src/file_asf.c')
-rw-r--r--src/file_asf.c79
1 files changed, 35 insertions, 44 deletions
diff --git a/src/file_asf.c b/src/file_asf.c
index 8f9fbd4..b3939e4 100644
--- a/src/file_asf.c
+++ b/src/file_asf.c
@@ -44,13 +44,6 @@ const file_hint_t file_hint_asf= {
.register_header_check=&register_header_check_asf
};
-static const unsigned char asf_header[4]= { 0x30,0x26,0xB2,0x75};
-
-static void register_header_check_asf(file_stat_t *file_stat)
-{
- register_header_check(0, asf_header,sizeof(asf_header), &header_check_asf, file_stat);
-}
-
struct asf_header_obj_s {
unsigned char object_id[16];
uint64_t object_size;
@@ -69,45 +62,43 @@ struct asf_file_prop_s {
static int header_check_asf(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 const unsigned char asf_header_id[16]= {
- 0x30, 0x26, 0xb2, 0x75, 0x8e, 0x66, 0xcf, 0x11,
- 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c
- };
- if(memcmp(buffer, asf_header_id, sizeof(asf_header_id))==0)
+ const struct asf_header_obj_s *asf_header_obj=(const struct asf_header_obj_s *)buffer;
+ const struct asf_file_prop_s *asf_file_prop=(const struct asf_file_prop_s*)(buffer+le64(asf_header_obj->object_size));
+ unsigned int i;
+ if(le64(asf_header_obj->object_size)<30 ||
+ le64(asf_header_obj->object_size)>buffer_size)
+ return 0;
+ reset_file_recovery(file_recovery_new);
+ file_recovery_new->extension=file_hint_asf.extension;
+ for(i=0;
+ i<le32(asf_header_obj->nbr_header_obj) &&
+ (const unsigned char *)(asf_file_prop+1) < buffer + buffer_size;
+ i++)
{
- unsigned int i;
- const struct asf_header_obj_s *asf_header_obj=(const struct asf_header_obj_s *)buffer;
- const struct asf_file_prop_s *asf_file_prop=(const struct asf_file_prop_s*)(asf_header_obj+1);
- reset_file_recovery(file_recovery_new);
- file_recovery_new->extension=file_hint_asf.extension;
- for(i=0;
- i<le32(asf_header_obj->nbr_header_obj) &&
- (const unsigned char *)(asf_file_prop+1) < buffer + buffer_size;
- i++)
+ static const unsigned char asf_file_prop_id[16]= {
+ 0xa1, 0xdc, 0xab, 0x8c, 0x47, 0xa9, 0xcf, 0x11,
+ 0x8e, 0xe4, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65
+ };
+ if(memcmp(asf_file_prop->object_id, asf_file_prop_id, sizeof(asf_file_prop_id))==0)
{
- static const unsigned char asf_file_prop_id[16]= {
- 0xa1, 0xdc, 0xab, 0x8c, 0x47, 0xa9, 0xcf, 0x11,
- 0x8e, 0xe4, 0x00, 0xc0, 0x0c, 0x20, 0x53, 0x65
- };
- if(memcmp(asf_file_prop->object_id, asf_file_prop_id, sizeof(asf_file_prop_id))==0)
- {
- file_recovery_new->calculated_file_size=le64(asf_file_prop->file_size);
- file_recovery_new->data_check=&data_check_size;
- file_recovery_new->file_check=&file_check_size;
- return 1;
- }
- if( le64(asf_file_prop->object_size)==0 ||
- le64(asf_file_prop->object_size)>1024*1024)
- return 1;
- asf_file_prop=(const struct asf_file_prop_s *)((const char *)asf_file_prop + le64(asf_file_prop->object_size));
+ file_recovery_new->calculated_file_size=le64(asf_file_prop->file_size);
+ file_recovery_new->data_check=&data_check_size;
+ file_recovery_new->file_check=&file_check_size;
+ return 1;
}
- return 1;
+ if( le64(asf_file_prop->object_size)==0 ||
+ le64(asf_file_prop->object_size)>1024*1024)
+ return 1;
+ asf_file_prop=(const struct asf_file_prop_s *)((const char *)asf_file_prop + le64(asf_file_prop->object_size));
}
- if(memcmp(buffer, asf_header, sizeof(asf_header))==0)
- {
- reset_file_recovery(file_recovery_new);
- file_recovery_new->extension=file_hint_asf.extension;
- return 1;
- }
- return 0;
+ return 1;
+}
+
+static void register_header_check_asf(file_stat_t *file_stat)
+{
+ static const unsigned char asf_header[16]= {
+ 0x30, 0x26, 0xb2, 0x75, 0x8e, 0x66, 0xcf, 0x11,
+ 0xa6, 0xd9, 0x00, 0xaa, 0x00, 0x62, 0xce, 0x6c
+ };
+ register_header_check(0, asf_header,sizeof(asf_header), &header_check_asf, file_stat);
}