summaryrefslogtreecommitdiffstats
path: root/src/file_r3d.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2014-07-26 22:37:13 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2014-07-26 22:37:13 +0200
commit93cb9ead06c54233114633f628a6a951b311e4ef (patch)
tree6fc68f6fba0442e43ac3fa96db797ef31c54b4c1 /src/file_r3d.c
parent09d486bc60f5128f6d6225e6c133545821e34f1f (diff)
PhotoRec: stricter check for .r3d
Diffstat (limited to 'src/file_r3d.c')
-rw-r--r--src/file_r3d.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/file_r3d.c b/src/file_r3d.c
index cbb172f..c0f4265 100644
--- a/src/file_r3d.c
+++ b/src/file_r3d.c
@@ -97,16 +97,26 @@ static data_check_t data_check_r3d(const unsigned char *buffer, const unsigned i
static int header_check_r3d(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)
{
- if(memcmp(&buffer[4], r3d_header1, sizeof(r3d_header1))==0 && buffer[0xa]=='R' && buffer[0xb]=='1')
+ const struct atom_struct *atom=(const struct atom_struct*)buffer;
+ if(be32(atom->size) < 8)
+ return 0;
+ if(buffer[0xa]=='R' && buffer[0xb]=='1')
{
reset_file_recovery(file_recovery_new);
file_recovery_new->extension=file_hint_r3d.extension;
file_recovery_new->file_rename=&file_rename_r3d;
- file_recovery_new->file_check=&file_check_size;
+ if(file_recovery_new->blocksize < 8)
+ return 1;
file_recovery_new->data_check=&data_check_r3d;
+ file_recovery_new->file_check=&file_check_size;
return 1;
}
- if(memcmp(&buffer[4], r3d_header2, sizeof(r3d_header2))==0 && buffer[0xa]=='R' && buffer[0xb]=='2')
+ return 0;
+}
+
+static int header_check_r3d_v2(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)
+{
+ if(buffer[0xa]=='R' && buffer[0xb]=='2')
{
reset_file_recovery(file_recovery_new);
file_recovery_new->extension=file_hint_r3d.extension;
@@ -138,5 +148,5 @@ static void file_rename_r3d(const char *old_filename)
static void register_header_check_r3d(file_stat_t *file_stat)
{
register_header_check(4, r3d_header1, sizeof(r3d_header1), &header_check_r3d, file_stat);
- register_header_check(4, r3d_header2, sizeof(r3d_header2), &header_check_r3d, file_stat);
+ register_header_check(4, r3d_header2, sizeof(r3d_header2), &header_check_r3d_v2, file_stat);
}