diff --git a/src/file_asf.c b/src/file_asf.c index 8f9fbd40..b3939e48 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=®ister_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]= { + 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; + inbr_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) + { + 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)); + } + 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 }; - if(memcmp(buffer, asf_header_id, sizeof(asf_header_id))==0) - { - 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; - inbr_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) - { - 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)); - } - return 1; - } - 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; + register_header_check(0, asf_header,sizeof(asf_header), &header_check_asf, file_stat); }