From 9f4bb675a6e4f2602cb64ed82e6b8e7fc236a47f Mon Sep 17 00:00:00 2001 From: Christophe Grenier Date: Sun, 26 Jan 2020 16:39:03 +0100 Subject: [PATCH] PhotoRec: src/file_gz.c, src/file_mp3.c: header_ignored_adv() must be called only once all checks have been done. --- src/file_gz.c | 35 ++++++++++++++++-------- src/file_mp3.c | 74 ++++++++++++++++++++++++-------------------------- 2 files changed, 59 insertions(+), 50 deletions(-) diff --git a/src/file_gz.c b/src/file_gz.c index 0ef52e02..ba5b112d 100644 --- a/src/file_gz.c +++ b/src/file_gz.c @@ -157,18 +157,7 @@ static int header_check_gz(const unsigned char *buffer, const unsigned int buffe } if(off >= 512 || off >= buffer_size) return 0; - if(file_recovery->file_stat!=NULL && - file_recovery->file_stat->file_hint==&file_hint_doc) - { - if(header_ignored_adv(file_recovery, file_recovery_new)==0) - return 0; - } - if(file_recovery->file_check==&file_check_bgzf) - { - header_ignored(file_recovery_new); - return 0; - } -#if defined(HAVE_ZLIB_H) && defined(HAVE_LIBZ) +#if defined(HAVE_ZLIB_H) && defined(HAVE_LIBZ) && !defined(__FRAMAC__) { static const unsigned char schematic_header[12]={ 0x0a, 0x00, 0x09, 'S', 'c', 'h', 'e', 'm', 'a', 't', 'i', 'c'}; @@ -207,6 +196,17 @@ static int header_check_gz(const unsigned char *buffer, const unsigned int buffe /* Probably too small to be a file */ if(d_stream.total_out < 16) return 0; + if(file_recovery->file_stat!=NULL && + file_recovery->file_stat->file_hint==&file_hint_doc) + { + if(header_ignored_adv(file_recovery, file_recovery_new)==0) + return 0; + } + if(file_recovery->file_check==&file_check_bgzf) + { + header_ignored(file_recovery_new); + return 0; + } buffer_uncompr[d_stream.total_out]='\0'; if(bgzf!=0) { @@ -297,6 +297,17 @@ static int header_check_gz(const unsigned char *buffer, const unsigned int buffe } } #else + if(file_recovery->file_stat!=NULL && + file_recovery->file_stat->file_hint==&file_hint_doc) + { + if(header_ignored_adv(file_recovery, file_recovery_new)==0) + return 0; + } + if(file_recovery->file_check==&file_check_bgzf) + { + header_ignored(file_recovery_new); + return 0; + } reset_file_recovery(file_recovery_new); file_recovery_new->min_filesize=22; file_recovery_new->time=le32(gz->mtime); diff --git a/src/file_mp3.c b/src/file_mp3.c index fb311ed5..11431da4 100644 --- a/src/file_mp3.c +++ b/src/file_mp3.c @@ -534,27 +534,6 @@ static int header_check_mp3(const unsigned char *buffer, const unsigned int buff (buffer[1]&0xFE)==0xF2 || (buffer[1]&0xFE)==0xE2))) return 0; - if(file_recovery->file_stat!=NULL) - { - if(file_recovery->file_stat->file_hint==&file_hint_mp3 -#if !defined(MAIN_mp3) - || file_recovery->file_stat->file_hint==&file_hint_mkv -#endif - ) - { - header_ignored(file_recovery_new); - return 0; - } -#if !defined(MAIN_mp3) - /* RGV values from TIFF may be similar to the beginning of an mp3 */ - if(file_recovery->file_stat->file_hint==&file_hint_tiff && - buffer[0]==buffer[3] && buffer[1]==buffer[4] && buffer[2]==buffer[5]) - { - if(header_ignored_adv(file_recovery, file_recovery_new)==0) - return 0; - } -#endif - } /*@ assert nbr == 0; */ /*@ @ loop invariant 0 <= nbr <= potential_frame_offset <= 2048 + 8065; @@ -603,28 +582,47 @@ static int header_check_mp3(const unsigned char *buffer, const unsigned int buff nbr++; } } - if(nbr>1) + if(nbr<=1) + return 0; + if(file_recovery->file_stat!=NULL) { - /*@ assert nbr > 1; */ - /*@ assert potential_frame_offset > 0; */ -#ifdef DEBUG_MP3 - log_info("header_check_mp3 mp3 found\n"); + if(file_recovery->file_stat->file_hint==&file_hint_mp3 +#if !defined(MAIN_mp3) + || file_recovery->file_stat->file_hint==&file_hint_mkv #endif - reset_file_recovery(file_recovery_new); - /*@ assert file_recovery_new->file_check == \null; */ - /*@ assert file_recovery_new->data_check == \null; */ - file_recovery_new->calculated_file_size=potential_frame_offset; - /*@ assert file_recovery_new->calculated_file_size > 0; */ - file_recovery_new->min_filesize=287; - file_recovery_new->extension=file_hint_mp3.extension; - if(file_recovery_new->blocksize >= 16) + ) { - file_recovery_new->data_check=&data_check_mp3; - file_recovery_new->file_check=&file_check_size; + header_ignored(file_recovery_new); + return 0; } - return 1; +#if !defined(MAIN_mp3) + /* RGV values from TIFF may be similar to the beginning of an mp3 */ + if(file_recovery->file_stat->file_hint==&file_hint_tiff && + buffer[0]==buffer[3] && buffer[1]==buffer[4] && buffer[2]==buffer[5]) + { + if(header_ignored_adv(file_recovery, file_recovery_new)==0) + return 0; + } +#endif } - return 0; + /*@ assert nbr > 1; */ + /*@ assert potential_frame_offset > 0; */ +#ifdef DEBUG_MP3 + log_info("header_check_mp3 mp3 found\n"); +#endif + reset_file_recovery(file_recovery_new); + /*@ assert file_recovery_new->file_check == \null; */ + /*@ assert file_recovery_new->data_check == \null; */ + file_recovery_new->calculated_file_size=potential_frame_offset; + /*@ assert file_recovery_new->calculated_file_size > 0; */ + file_recovery_new->min_filesize=287; + file_recovery_new->extension=file_hint_mp3.extension; + if(file_recovery_new->blocksize >= 16) + { + file_recovery_new->data_check=&data_check_mp3; + file_recovery_new->file_check=&file_check_size; + } + return 1; } /*@