Ignore excess bytes, if length of input file is *not* an integer multiple of 8.
This commit is contained in:
parent
c530556e94
commit
fb4f429493
@ -358,6 +358,10 @@ static int decrypt(const char* const passphrase, const CHR* const input_path, co
|
||||
FPUTS(T("Error: Input file is too small! Truncated?\n\n"), stderr);
|
||||
goto clean_up;
|
||||
}
|
||||
else if ((file_size % sizeof(uint64_t)) != 0)
|
||||
{
|
||||
FPRINTF(stderr, T("Warning: File size is *not* an integer multiple of %u, ignoring excess bytes!\n\n"), sizeof(uint64_t));
|
||||
}
|
||||
|
||||
FPUTS(T("Decrypting file contents, please be patient... "), stderr);
|
||||
fflush(stderr);
|
||||
@ -379,7 +383,7 @@ static int decrypt(const char* const passphrase, const CHR* const input_path, co
|
||||
clock_t clk_now, clk_update = clock();
|
||||
uint64_t crc_actual = CRC_INITIALIZER, bytes_read = sizeof(uint64_t);
|
||||
uint8_t buffer[BUFFER_SIZE];
|
||||
const uint64_t read_limit = file_size - (2U * sizeof(uint64_t));
|
||||
const uint64_t read_limit = round_down(file_size, sizeof(uint64_t)) - (2U * sizeof(uint64_t));
|
||||
|
||||
FPRINTF(stderr, T("%5.1f%% "), 0.0);
|
||||
fflush(stderr);
|
||||
|
@ -177,3 +177,13 @@ const CHR* get_file_name(const CHR* path)
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
// ==========================================================================
|
||||
// Math functions
|
||||
// ==========================================================================
|
||||
|
||||
uint64_t round_down(const uint64_t value, const uint64_t base)
|
||||
{
|
||||
const uint64_t modulus = value % base;
|
||||
return modulus ? (value - modulus) : value;
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ uint64_t swap_bytes_u64(const uint64_t value);
|
||||
char* CHR_to_utf8(const CHR *const input);
|
||||
uint64_t get_file_size(FILE* const file);
|
||||
const CHR *get_file_name(const CHR *path);
|
||||
uint64_t round_down(const uint64_t value, const uint64_t base);
|
||||
|
||||
#define GET_NIBBLE(X) ((X) & 0x0F)
|
||||
#define SET_NIBBLE(X, Y) do { X = ((X) & 0xF0) | ((Y) & 0x0F); } while(0)
|
||||
|
Loading…
Reference in New Issue
Block a user