From 2f5c6a39a9ad78ede9c6ae00adbf728623080641 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Sat, 9 Jan 2016 10:06:37 +0100 Subject: [PATCH] Fix unaligned memory access in import After extent conversion, the hash is not not aligned anymore, and we cannot cast anymore to uint32. --- cmdline/import.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmdline/import.c b/cmdline/import.c index e9c8cc51..0741dd63 100644 --- a/cmdline/import.c +++ b/cmdline/import.c @@ -48,7 +48,8 @@ int import_block_prevhash_compare(const void* void_arg, const void* void_data) */ static inline tommy_uint32_t import_block_hash(const unsigned char* hash) { - return *(const tommy_uint32_t*)hash; + /* the hash data is not aligned, and we cannot access it with a direct cast */ + return hash[0] | ((uint32_t)hash[1] << 8) | ((uint32_t)hash[2] << 16) | ((uint32_t)hash[3] << 24); } static void import_file(struct snapraid_state* state, const char* path, uint64_t size)