summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2019-09-21 08:51:12 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2019-09-21 08:51:12 +0200
commit153269e044bef851b706f2306a936331c3a5e94c (patch)
tree764e79dd801be1d8fa31c1cb708a474839d57b8b
parent5eb2d5a0547f3bb0b77b99eb90563aca73ba76dd (diff)
PhotoRec: set file_recovery_new->location.start before calling header_check()
-rw-r--r--src/filegen.c15
-rw-r--r--src/phbf.c2
-rw-r--r--src/phbs.c1
-rw-r--r--src/photorec_check_header.h2
4 files changed, 10 insertions, 10 deletions
diff --git a/src/filegen.c b/src/filegen.c
index 63a27d6..deba440 100644
--- a/src/filegen.c
+++ b/src/filegen.c
@@ -317,7 +317,6 @@ void reset_file_recovery(file_recovery_t *file_recovery)
file_recovery->file_size=0;
file_recovery->location.list.prev=&file_recovery->location.list;
file_recovery->location.list.next=&file_recovery->location.list;
- file_recovery->location.start=0;
file_recovery->location.end=0;
file_recovery->location.data=0;
file_recovery->extension=NULL;
@@ -330,7 +329,6 @@ void reset_file_recovery(file_recovery_t *file_recovery)
file_recovery->offset_ok=0;
file_recovery->checkpoint_status=0;
file_recovery->checkpoint_offset=0;
-// file_recovery->blocksize=512;
file_recovery->flags=0;
file_recovery->extra=0;
}
@@ -618,7 +616,7 @@ int header_ignored_adv(const file_recovery_t *file_recovery, const file_recovery
}
if(file_recovery->handle==NULL)
{
- if(file_recovery_new->location.start==0 || offset_skipped_header==0)
+ if(file_recovery_new->location.start < offset_skipped_header || offset_skipped_header==0)
{
offset_skipped_header=file_recovery_new->location.start;
}
@@ -641,7 +639,7 @@ int header_ignored_adv(const file_recovery_t *file_recovery, const file_recovery
}
if(fr_test.file_size>0)
return 1;
- if(file_recovery_new->location.start==0 || offset_skipped_header==0)
+ if(file_recovery_new->location.start < offset_skipped_header || offset_skipped_header==0)
{
offset_skipped_header=file_recovery_new->location.start;
}
@@ -655,7 +653,7 @@ void header_ignored(const file_recovery_t *file_recovery_new)
offset_skipped_header=0;
return ;
}
- if(file_recovery_new->location.start==0 || offset_skipped_header==0)
+ if(file_recovery_new->location.start < offset_skipped_header || offset_skipped_header==0)
offset_skipped_header=file_recovery_new->location.start;
}
@@ -679,7 +677,7 @@ void get_prev_location_smart(alloc_data_t *list_search_space, alloc_data_t **cur
if(file_space->start < prev_location)
break;
}
-#ifdef DEBUG_HEADER_CHECK
+#ifdef DEBUG_PREV_LOCATION
log_info("get_prev_location_smart: reset offset_skipped_header=%llu, offset=%llu\n",
(long long unsigned)(offset_skipped_header/512),
(long long unsigned)(*offset/512));
@@ -692,17 +690,18 @@ void get_prev_location_smart(alloc_data_t *list_search_space, alloc_data_t **cur
offset_skipped_header=0;
return;
}
+ *current_search_space=file_space;
if(file_space->start < prev_location || file_space->start < offset_skipped_header)
{
-#ifdef DEBUG_HEADER_CHECK
+#ifdef DEBUG_PREV_LOCATION
log_info("get_prev_location_smart: file_space->start < prev_location=%llu (in 512-bytes sectors), offset=%llu\n",
(long long unsigned)(prev_location/512),
(long long unsigned)(*offset/512));
#endif
+ *offset=offset_skipped_header;
offset_skipped_header=0;
return ;
}
- *current_search_space=file_space;
*offset=file_space->start;
}
}
diff --git a/src/phbf.c b/src/phbf.c
index 5d501a3..523abe4 100644
--- a/src/phbf.c
+++ b/src/phbf.c
@@ -170,6 +170,7 @@ pstatus_t photorec_bf(struct ph_param *params, const struct ph_options *options,
file_recovery_t file_recovery_new;
// memset(&file_recovery_new, 0, sizeof(file_recovery_t));
file_recovery_new.blocksize=blocksize;
+ file_recovery_new.location.start=offset;
file_recovery_new.file_stat=NULL;
td_list_for_each(tmpl, &file_check_list.list)
{
@@ -190,7 +191,6 @@ pstatus_t photorec_bf(struct ph_param *params, const struct ph_options *options,
}
if(file_recovery_new.file_stat!=NULL)
{
- file_recovery_new.location.start=offset;
if(options->verbose>0)
{
log_info("%s header found at sector %lu\n",
diff --git a/src/phbs.c b/src/phbs.c
index b1135d8..9ce2d0d 100644
--- a/src/phbs.c
+++ b/src/phbs.c
@@ -100,6 +100,7 @@ pstatus_t photorec_find_blocksize(struct ph_param *params, const struct ph_optio
{
file_recovery_t file_recovery_new;
file_recovery_new.blocksize=blocksize;
+ file_recovery_new.location.start=offset;
if(file_recovery.file_stat!=NULL && file_recovery.file_stat->file_hint==&file_hint_tar &&
header_check_tar(buffer-0x200,0x200,0,&file_recovery,&file_recovery_new))
{ /* Currently saving a tar, do not check the data for know header */
diff --git a/src/photorec_check_header.h b/src/photorec_check_header.h
index 7767ca1..6522d9f 100644
--- a/src/photorec_check_header.h
+++ b/src/photorec_check_header.h
@@ -97,7 +97,6 @@ static pstatus_t photorec_header_found(file_recovery_t *file_recovery_new, file_
*file_recovered=PFSTATUS_BAD;
if(file_recovery_new->file_stat==NULL || file_recovery_new->file_stat->file_hint==NULL)
return PSTATUS_OK;
- file_recovery_new->location.start=offset;
if(file_recovery->file_stat!=NULL)
{
if(options->verbose > 1)
@@ -132,6 +131,7 @@ inline static pstatus_t photorec_check_header(file_recovery_t *file_recovery, st
const unsigned int read_size=(blocksize>65536?blocksize:65536);
file_recovery_t file_recovery_new;
file_recovery_new.blocksize=blocksize;
+ file_recovery_new.location.start=offset;
if(file_recovery->file_stat!=NULL && file_recovery->file_stat->file_hint==&file_hint_tar &&
header_check_tar(buffer-0x200,0x200, 0, file_recovery, &file_recovery_new))
{ /* Currently saving a tar, do not check the data for know header */