src/file_evt.c: fix frama-c annotations

This commit is contained in:
Christophe Grenier 2021-01-29 21:16:33 +01:00
parent cd6dec4139
commit 590cf7dab3

View file

@ -33,8 +33,8 @@
#include "filegen.h"
#include "log.h"
/*@ requires \valid(file_stat); */
static void register_header_check_evt(file_stat_t *file_stat);
static int header_check_evt(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_evt= {
.extension="evt",
@ -50,6 +50,17 @@ struct evt_chunk {
uint32_t id;
} __attribute__ ((gcc_struct, __packed__));
/*@
@ requires buffer_size > 0;
@ requires (buffer_size&1)==0;
@ requires \valid_read(buffer+(0..buffer_size-1));
@ requires \valid(file_recovery);
@ requires file_recovery->data_check==&data_check_evt;
@ requires file_recovery->calculated_file_size <= PHOTOREC_MAX_FILE_SIZE;
@ requires \separated(buffer, file_recovery);
@ ensures \result == DC_CONTINUE || \result == DC_STOP;
@ assigns file_recovery->calculated_file_size;
@*/
static data_check_t data_check_evt(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
/*@
@ -58,7 +69,8 @@ static data_check_t data_check_evt(const unsigned char *buffer, const unsigned i
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
file_recovery->calculated_file_size + 8 < file_recovery->file_size + buffer_size/2)
{
const unsigned int i=file_recovery->calculated_file_size - file_recovery->file_size + buffer_size/2;
const unsigned int i=file_recovery->calculated_file_size + buffer_size/2 - file_recovery->file_size;
/*@ assert 0 <= i < buffer_size - 8; */
const struct evt_chunk *chunk=(const struct evt_chunk *)&buffer[i];
if((buffer[i+4]=='L' && buffer[i+5]=='f' && buffer[i+6]=='L' && buffer[i+7]=='e') ||
(buffer[i+4]==0x11 && buffer[i+5]==0x11 && buffer[i+6]==0x11 && buffer[i+7]==0x11) ||
@ -84,6 +96,16 @@ static data_check_t data_check_evt(const unsigned char *buffer, const unsigned i
return DC_CONTINUE;
}
/*@
@ requires buffer_size >= 8;
@ requires \valid_read(buffer+(0..buffer_size-1));
@ requires valid_file_recovery(file_recovery);
@ requires \valid(file_recovery_new);
@ requires file_recovery_new->blocksize > 0;
@ requires separation: \separated(&file_hint_evt, buffer+(..), file_recovery, file_recovery_new);
@ ensures \result!=0 ==> valid_file_recovery(file_recovery_new);
@ assigns *file_recovery_new;
@*/
static int header_check_evt(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 struct evt_chunk *chunk=(const struct evt_chunk *)buffer;