summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/file_ace.c3
-rw-r--r--src/file_jpg.c15
-rw-r--r--src/file_nk2.c1
-rw-r--r--src/file_xm.c1
-rw-r--r--src/file_zip.c4
-rw-r--r--src/filegen.c14
-rw-r--r--src/filegen.h1
7 files changed, 31 insertions, 8 deletions
diff --git a/src/file_ace.c b/src/file_ace.c
index 20f56d5..6309e95 100644
--- a/src/file_ace.c
+++ b/src/file_ace.c
@@ -72,8 +72,9 @@ static void file_check_ace(file_recovery_t *file_recovery)
{
fseek(file_recovery->handle, 0, SEEK_SET);
+ file_recovery->offset_error = 0;
+ file_recovery->offset_ok = 0;
file_recovery->file_size = 0;
- file_recovery->offset_error=0;
#ifdef DEBUG_ACE
log_trace("file_check_ace\n");
#endif
diff --git a/src/file_jpg.c b/src/file_jpg.c
index 66e11de..cdb3131 100644
--- a/src/file_jpg.c
+++ b/src/file_jpg.c
@@ -33,6 +33,7 @@
#include <stdlib.h>
#endif
#include <stdio.h>
+#include <errno.h>
#include "types.h"
#ifdef HAVE_SETJMP_H
#include <setjmp.h>
@@ -205,6 +206,7 @@ typedef struct {
JOCTET * buffer; /* start of buffer */
boolean start_of_file; /* have we gotten any data yet? */
unsigned long int file_size;
+ unsigned long int offset_ok;
} my_source_mgr;
#define JPG_INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */
@@ -224,6 +226,7 @@ static void jpg_init_source (j_decompress_ptr cinfo)
*/
src->start_of_file = TRUE;
src->file_size = 0;
+ src->offset_ok = 0;
}
@@ -307,6 +310,7 @@ static void jpg_skip_input_data (j_decompress_ptr cinfo, long num_bytes)
* any trouble anyway --- large skips are infrequent.
*/
if (num_bytes > 0) {
+ src->offset_ok=src->file_size - src->pub.bytes_in_buffer;
while (num_bytes > (long) src->pub.bytes_in_buffer) {
num_bytes -= (long) src->pub.bytes_in_buffer;
(void) jpg_fill_input_buffer(cinfo);
@@ -424,7 +428,8 @@ static void file_check_jpg(file_recovery_t *file_recovery)
my_source_mgr * src;
src = (my_source_mgr *) cinfo.src;
jpeg_size=src->file_size - src->pub.bytes_in_buffer;
- // log_error("JPG error at offset %llu\n", (long long unsigned)jpeg_size);
+ log_error("JPG error, ok at %llu - bad at %llu\n",
+ (long long unsigned)src->offset_ok, (long long unsigned)jpeg_size);
jpeg_destroy_decompress(&cinfo);
if(jpeg_size>0)
file_recovery->offset_error=jpeg_size;
@@ -449,6 +454,9 @@ static void file_check_jpg(file_recovery_t *file_recovery)
((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
while (cinfo.output_scanline < cinfo.output_height)
{
+ my_source_mgr * src;
+ src = (my_source_mgr *) cinfo.src;
+ src->offset_ok=src->file_size - src->pub.bytes_in_buffer;
(void)jpeg_read_scanlines(&cinfo, buffer, 1);
}
(void) jpeg_finish_decompress(&cinfo);
@@ -554,7 +562,10 @@ static void jpg_check_structure(file_recovery_t *file_recovery, const unsigned i
*(sep+1)='t';
if((out=fopen(thumbname,"wb"))!=NULL)
{
- fwrite(thumb_data, thumb_size, 1, out);
+ if(fwrite(thumb_data, thumb_size, 1, out) < 1)
+ {
+ log_error("Can't write to %s: %s\n", thumbname, strerror(errno));
+ }
fclose(out);
}
else
diff --git a/src/file_nk2.c b/src/file_nk2.c
index 0698190..c103ae9 100644
--- a/src/file_nk2.c
+++ b/src/file_nk2.c
@@ -112,6 +112,7 @@ static void file_check_nk2(file_recovery_t *fr)
fseek(fr->handle, 0, SEEK_SET);
fr->file_size = 0;
fr->offset_error=0;
+ fr->offset_ok=0;
if (fread(&nk2h, sizeof(nk2h), 1, fr->handle)!=1)
{
fr->offset_error=fr->file_size;
diff --git a/src/file_xm.c b/src/file_xm.c
index 7816b11..5b18e96 100644
--- a/src/file_xm.c
+++ b/src/file_xm.c
@@ -148,6 +148,7 @@ static void file_check_xm(file_recovery_t *fr)
fr->file_size = 0;
fr->offset_error=0;
+ fr->offset_ok=0;
if (fseek(fr->handle, 70, SEEK_SET) == -1)
return;
diff --git a/src/file_zip.c b/src/file_zip.c
index 9bd06e9..b147d05 100644
--- a/src/file_zip.c
+++ b/src/file_zip.c
@@ -482,9 +482,11 @@ static void file_check_zip(file_recovery_t *fr)
fseek(fr->handle, 0, SEEK_SET);
fr->file_size = 0;
fr->offset_error=0;
+ fr->offset_ok=0;
while (1)
{
+ uint64_t file_size_old;
uint32_t header;
int status;
@@ -504,6 +506,7 @@ static void file_check_zip(file_recovery_t *fr)
log_flush();
#endif
fr->file_size += 4;
+ file_size_old=fr->file_size;
switch (header)
{
@@ -550,6 +553,7 @@ static void file_check_zip(file_recovery_t *fr)
/* Only end of central dir is end of archive, 64b version of it is before */
if (header==ZIP_END_CENTRAL_DIR)
return;
+ fr->offset_ok=file_size_old;
}
}
diff --git a/src/filegen.c b/src/filegen.c
index 8e939ab..bdd7e10 100644
--- a/src/filegen.c
+++ b/src/filegen.c
@@ -34,9 +34,7 @@
#include "types.h"
#include "common.h"
#include "filegen.h"
-#ifdef DEBUG_HEADER_CHECK
#include "log.h"
-#endif
static file_check_t file_check_plist={
.list = TD_LIST_HEAD_INIT(file_check_plist.list)
@@ -46,7 +44,7 @@ file_check_list_t file_check_list={
.list = TD_LIST_HEAD_INIT(file_check_list.list)
};
-static void index_header_check(void);
+static unsigned int index_header_check(void);
static int file_check_cmp(const struct td_list_head *a, const struct td_list_head *b)
{
@@ -125,17 +123,20 @@ static void index_header_check_aux(file_check_t *file_check_new)
file_check_add_tail(file_check_new, &file_check_list);
}
-static void index_header_check(void)
+static unsigned int index_header_check(void)
{
struct td_list_head *tmp;
struct td_list_head *next;
+ unsigned int nbr=0;
td_list_for_each_prev_safe(tmp, next, &file_check_plist.list)
{
file_check_t *current_check;
current_check=td_list_entry(tmp, file_check_t, list);
td_list_del(tmp);
index_header_check_aux(current_check);
+ nbr++;
}
+ return nbr;
}
void free_header_check(void)
@@ -307,6 +308,7 @@ void reset_file_recovery(file_recovery_t *file_recovery)
file_recovery->file_check=NULL;
file_recovery->file_rename=NULL;
file_recovery->offset_error=0;
+ file_recovery->offset_ok=0;
}
file_stat_t * init_file_stats(file_enable_t *files_enable)
@@ -314,6 +316,7 @@ file_stat_t * init_file_stats(file_enable_t *files_enable)
file_stat_t *file_stats;
file_enable_t *file_enable;
unsigned int enable_count=1; /* Lists are terminated by NULL */
+ unsigned int sign_nbr;
for(file_enable=files_enable;file_enable->file_hint!=NULL;file_enable++)
{
if(file_enable->enable>0)
@@ -335,8 +338,9 @@ file_stat_t * init_file_stats(file_enable_t *files_enable)
enable_count++;
}
}
- index_header_check();
+ sign_nbr=index_header_check();
file_stats[enable_count].file_hint=NULL;
+ log_info("%u first-level signatures enabled\n", sign_nbr);
return file_stats;
}
diff --git a/src/filegen.h b/src/filegen.h
index 812eeeb..dc3ba36 100644
--- a/src/filegen.h
+++ b/src/filegen.h
@@ -71,6 +71,7 @@ struct file_recovery_struct
uint64_t file_size_on_disk;
const char *extension;
uint64_t min_filesize;
+ uint64_t offset_ok;
uint64_t offset_error;
uint64_t calculated_file_size;
int (*data_check)(const unsigned char*buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);