summaryrefslogtreecommitdiffstats
path: root/src/file_vdi.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2014-07-26 22:43:27 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2014-07-26 22:43:27 +0200
commitc7aae7f0b379d85b554bb5e61f97070bf9259182 (patch)
tree6dde7eac82ab5b4267640b9fdffa045e181be22b /src/file_vdi.c
parent363531f61179c99be6a7febc47e1cba6b9e1956e (diff)
PhotoRec: stricter check for .vdi
Diffstat (limited to 'src/file_vdi.c')
-rw-r--r--src/file_vdi.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/file_vdi.c b/src/file_vdi.c
index 06ad421..b9525f1 100644
--- a/src/file_vdi.c
+++ b/src/file_vdi.c
@@ -32,7 +32,6 @@
#include "common.h"
static void register_header_check_vdi(file_stat_t *file_stat);
-static int header_check_vdi(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_vdi= {
.extension="vdi",
@@ -44,13 +43,6 @@ const file_hint_t file_hint_vdi= {
.register_header_check=&register_header_check_vdi
};
-static const unsigned char vdi_header[4]= {0x7f, 0x10, 0xda, 0xbe};
-
-static void register_header_check_vdi(file_stat_t *file_stat)
-{
- register_header_check(0x40, vdi_header,sizeof(vdi_header), &header_check_vdi, file_stat);
-}
-
/* Image version. */
#define VDI_VERSION_1_1 0x00010001
@@ -90,8 +82,10 @@ typedef struct {
static int header_check_vdi(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 VdiHeader *header=(const VdiHeader *)buffer;
- if(memcmp(&buffer[0x40], vdi_header, sizeof(vdi_header))==0 && le32(header->version) == VDI_VERSION_1_1)
+ if(le32(header->version) == VDI_VERSION_1_1)
{
+ if(le32(header->offset_data) < sizeof(VdiHeader))
+ return 0;
reset_file_recovery(file_recovery_new);
file_recovery_new->extension=file_hint_vdi.extension;
if(le32(header->image_type) == VDI_TYPE_STATIC)
@@ -104,3 +98,9 @@ static int header_check_vdi(const unsigned char *buffer, const unsigned int buff
}
return 0;
}
+
+static void register_header_check_vdi(file_stat_t *file_stat)
+{
+ static const unsigned char vdi_header[4]= {0x7f, 0x10, 0xda, 0xbe};
+ register_header_check(0x40, vdi_header,sizeof(vdi_header), &header_check_vdi, file_stat);
+}