mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-26 02:49:02 -04:00
Change the BLOCK_HASH_SIZE type to avoid potential overflow
This commit is contained in:
parent
d9c5e0c9b2
commit
4a37e3fece
7 changed files with 13 additions and 12 deletions
|
|
@ -1334,7 +1334,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
|
|||
failed[failed_count].handle = &handle[j];
|
||||
++failed_count;
|
||||
|
||||
log_tag("error:%u:%s:%s: Data error at position %u, diff hash bits %u/%u\n", i, disk->name, esc_tag(file->sub), file_pos, diff, BLOCK_HASH_SIZE * 8);
|
||||
log_tag("error:%u:%s:%s: Data error at position %u, diff hash bits %u/%zu\n", i, disk->name, esc_tag(file->sub), file_pos, diff, BLOCK_HASH_SIZE * 8);
|
||||
++silent_error;
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
/****************************************************************************/
|
||||
/* snapraid */
|
||||
|
||||
int BLOCK_HASH_SIZE = HASH_MAX;
|
||||
size_t BLOCK_HASH_SIZE = HASH_MAX;
|
||||
|
||||
struct snapraid_content* content_alloc(const char* path, uint64_t dev)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ struct snapraid_filter {
|
|||
*
|
||||
* At max HASH_MAX.
|
||||
*/
|
||||
extern int BLOCK_HASH_SIZE;
|
||||
extern size_t BLOCK_HASH_SIZE;
|
||||
|
||||
/**
|
||||
* Block of a file.
|
||||
|
|
@ -646,7 +646,7 @@ int filter_content(tommy_list* contentlist, const char* path);
|
|||
*/
|
||||
static inline int hash_is_invalid(const unsigned char* hash)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
/* if the hash is reduced, we cannot grant that it's a specific kind of hash */
|
||||
if (BLOCK_HASH_SIZE != HASH_MAX)
|
||||
|
|
@ -668,7 +668,7 @@ static inline int hash_is_invalid(const unsigned char* hash)
|
|||
*/
|
||||
static inline int hash_is_zero(const unsigned char* hash)
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
|
||||
/* if the hash is reduced, we cannot grant that it's a specific kind of hash */
|
||||
if (BLOCK_HASH_SIZE != HASH_MAX)
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@
|
|||
#ifdef __MINGW32__
|
||||
#if defined(__USE_MINGW_ANSI_STDIO) && __USE_MINGW_ANSI_STDIO == 1
|
||||
#define attribute_printf gnu_printf /* GNU format */
|
||||
#define printf __mingw_printf
|
||||
#else
|
||||
#define attribute_printf ms_printf /* MSVCRT format */
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -485,12 +485,12 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par
|
|||
|
||||
/* it's a silent error only if we are dealing with synced files */
|
||||
if (file_is_unsynced) {
|
||||
log_tag("error:%u:%s:%s: Data error at position %u, diff hash bits %u/%u\n", blockcur, disk->name, esc_tag(file->sub), file_pos, diff, BLOCK_HASH_SIZE * 8);
|
||||
log_tag("error:%u:%s:%s: Data error at position %u, diff hash bits %u/%zu\n", blockcur, disk->name, esc_tag(file->sub), file_pos, diff, BLOCK_HASH_SIZE * 8);
|
||||
++soft_error;
|
||||
error_on_this_block = 1;
|
||||
} else {
|
||||
log_tag("error_data:%u:%s:%s: Data error at position %u, diff hash bits %u/%u\n", blockcur, disk->name, esc_tag(file->sub), file_pos, diff, BLOCK_HASH_SIZE * 8);
|
||||
log_error(EDATA, "Data error in file '%s' at position '%u', diff hash bits %u/%u\n", task->path, file_pos, diff, BLOCK_HASH_SIZE * 8);
|
||||
log_tag("error_data:%u:%s:%s: Data error at position %u, diff hash bits %u/%zu\n", blockcur, disk->name, esc_tag(file->sub), file_pos, diff, BLOCK_HASH_SIZE * 8);
|
||||
log_error(EDATA, "Data error in file '%s' at position '%u', diff hash bits %u/%zu\n", task->path, file_pos, diff, BLOCK_HASH_SIZE * 8);
|
||||
++silent_error;
|
||||
silent_error_on_this_block = 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2964,7 +2964,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S
|
|||
BLOCK_HASH_SIZE = hash_size;
|
||||
}
|
||||
|
||||
if ((int)hash_size != BLOCK_HASH_SIZE) {
|
||||
if (hash_size != BLOCK_HASH_SIZE) {
|
||||
/* LCOV_EXCL_START */
|
||||
decoding_error(path, f);
|
||||
log_fatal(EUSER, "Mismatching 'hashsize' specification in the content file!\n");
|
||||
|
|
@ -5659,7 +5659,7 @@ void generate_configuration(const char* path)
|
|||
printf("blocksize %u\n", state.block_size / KIBI);
|
||||
printf("\n");
|
||||
printf("# Use this hashsize\n");
|
||||
printf("hashsize %u\n", BLOCK_HASH_SIZE);
|
||||
printf("hashsize %zu\n", BLOCK_HASH_SIZE);
|
||||
printf("\n");
|
||||
for (l = 0; l < state.level; ++l) {
|
||||
printf("# Set the correct path for the %s files\n", lev_name(l));
|
||||
|
|
|
|||
|
|
@ -966,8 +966,8 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari
|
|||
continue;
|
||||
} else { /* otherwise it's a BLK with silent error */
|
||||
unsigned diff = memdiff(hash, block->hash, BLOCK_HASH_SIZE);
|
||||
log_tag("error_data:%u:%s:%s: Data error at position %u, diff hash bits %u/%u\n", blockcur, disk->name, esc_tag(file->sub), file_pos, diff, BLOCK_HASH_SIZE * 8);
|
||||
log_error(EDATA, "Data error in file '%s' at position '%u', diff hash bits %u/%u\n", task->path, file_pos, diff, BLOCK_HASH_SIZE * 8);
|
||||
log_tag("error_data:%u:%s:%s: Data error at position %u, diff hash bits %u/%zu\n", blockcur, disk->name, esc_tag(file->sub), file_pos, diff, BLOCK_HASH_SIZE * 8);
|
||||
log_error(EDATA, "Data error in file '%s' at position '%u', diff hash bits %u/%zu\n", task->path, file_pos, diff, BLOCK_HASH_SIZE * 8);
|
||||
|
||||
/* save the failed block for the fix */
|
||||
failed[failed_count].index = diskcur;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue