mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-25 18:40:19 -04:00
Reject parity sizes exceeding data_off_t range and remove redundant block size casts
This commit is contained in:
parent
149b408c38
commit
bcc06e10c6
6 changed files with 14 additions and 9 deletions
|
|
@ -3087,7 +3087,7 @@ int state_check(struct snapraid_state* state, int fix, block_off_t blockstart, b
|
|||
*/
|
||||
|
||||
blockmax = parity_allocated_size(state);
|
||||
size = blockmax * (data_off_t)state->block_size;
|
||||
size = blockmax * state->block_size;
|
||||
|
||||
if (blockstart > blockmax) {
|
||||
/* LCOV_EXCL_START */
|
||||
|
|
|
|||
|
|
@ -375,7 +375,7 @@ ssize_t handle_read(struct snapraid_handle* handle, block_off_t file_pos, unsign
|
|||
unsigned count;
|
||||
int ret;
|
||||
|
||||
offset = file_pos * (data_off_t)block_size;
|
||||
offset = file_pos * block_size;
|
||||
|
||||
if (!out_missing)
|
||||
out_missing = log_error;
|
||||
|
|
@ -456,7 +456,7 @@ int handle_write(struct snapraid_handle* handle, block_off_t file_pos, unsigned
|
|||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
||||
offset = file_pos * (data_off_t)block_size;
|
||||
offset = file_pos * block_size;
|
||||
|
||||
write_size = file_block_size(handle->file, file_pos, block_size);
|
||||
|
||||
|
|
|
|||
|
|
@ -44,6 +44,11 @@ block_off_t parity_allocated_size(struct snapraid_state* state)
|
|||
parity_block = block;
|
||||
}
|
||||
|
||||
if (parity_block > (block_off_t)INT64_MAX / state->block_size) {
|
||||
log_fatal(ESOFT, "Parity with %" PRIu64 " blocks is too large for block size %u.\n", parity_block, state->block_size);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
return parity_block;
|
||||
}
|
||||
|
||||
|
|
@ -1083,7 +1088,7 @@ int parity_write(struct snapraid_parity_handle* handle, block_off_t pos, unsigne
|
|||
unsigned count;
|
||||
int ret;
|
||||
|
||||
offset = pos * (data_off_t)block_size;
|
||||
offset = pos * block_size;
|
||||
|
||||
split = parity_split_find(handle, &offset);
|
||||
if (!split) {
|
||||
|
|
@ -1177,7 +1182,7 @@ int parity_read(struct snapraid_parity_handle* handle, block_off_t pos, unsigned
|
|||
struct snapraid_split_handle* split;
|
||||
int ret;
|
||||
|
||||
offset = pos * (data_off_t)block_size;
|
||||
offset = pos * block_size;
|
||||
|
||||
split = parity_split_find(handle, &offset);
|
||||
if (!split) {
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ int state_search_fetch(struct snapraid_state* state, int prevhash, struct snapra
|
|||
arg.block = missing_block;
|
||||
arg.file = missing_file;
|
||||
arg.buffer = buffer;
|
||||
arg.offset = state->block_size * (data_off_t)missing_file_pos;
|
||||
arg.offset = state->block_size * missing_file_pos;
|
||||
arg.read_size = file_block_size(missing_file, missing_file_pos, state->block_size);
|
||||
arg.prevhash = prevhash;
|
||||
|
||||
|
|
|
|||
|
|
@ -2950,7 +2950,7 @@ static void state_read_content(struct snapraid_state* state, const char* path, S
|
|||
* Allocate without initializing blocks. This deleted run sets every
|
||||
* state and hash before the file is inserted in the extent map.
|
||||
*/
|
||||
deleted = file_alloc(state->block_size, "<deleted>", v_count * (data_off_t)state->block_size, 0, 0, 0);
|
||||
deleted = file_alloc(state->block_size, "<deleted>", v_count * state->block_size, 0, 0, 0);
|
||||
|
||||
/* mark the file as deleted */
|
||||
file_flag_set(deleted, FILE_IS_DELETED);
|
||||
|
|
|
|||
|
|
@ -2019,11 +2019,11 @@ int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t
|
|||
* but must not be shorter than used_size (which indicates missing parity).
|
||||
*/
|
||||
blockmax = parity_allocated_size(state);
|
||||
size = blockmax * (data_off_t)state->block_size;
|
||||
size = blockmax * state->block_size;
|
||||
|
||||
/* minimum size of the parity files we expect */
|
||||
used_paritymax = parity_used_size(state);
|
||||
used_parity_size = used_paritymax * (data_off_t)state->block_size;
|
||||
used_parity_size = used_paritymax * state->block_size;
|
||||
|
||||
if (blockstart > blockmax) {
|
||||
/* LCOV_EXCL_START */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue