From 6f083b7a921a4ff5df1a5029ba4ee37dcfa2e33a Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Sun, 23 Jun 2019 09:04:42 +0200 Subject: [PATCH] src/api2/backup/upload_chunk.rs: compute crc on upload --- src/api2/backup/upload_chunk.rs | 5 ++++- src/backup/data_chunk.rs | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/api2/backup/upload_chunk.rs b/src/api2/backup/upload_chunk.rs index cd9bc55b..ce8fcdce 100644 --- a/src/api2/backup/upload_chunk.rs +++ b/src/api2/backup/upload_chunk.rs @@ -53,10 +53,13 @@ impl Future for UploadChunk { bail!("uploaded chunk has unexpected size."); } - let chunk = DataChunk::from_raw(raw_data, self.digest)?; + let mut chunk = DataChunk::from_raw(raw_data, self.digest)?; chunk.verify_unencrypted(self.size as usize)?; + // always comput CRC at server side + chunk.set_crc(chunk.compute_crc()); + let (is_duplicate, compressed_size) = self.store.insert_chunk(&chunk)?; return Ok(Async::Ready((self.digest, self.size, compressed_size as u32, is_duplicate))) diff --git a/src/backup/data_chunk.rs b/src/backup/data_chunk.rs index ccc764dc..08f02959 100644 --- a/src/backup/data_chunk.rs +++ b/src/backup/data_chunk.rs @@ -54,7 +54,7 @@ impl DataChunk { } /// compute the CRC32 checksum - pub fn compute_crc(&mut self) -> u32 { + pub fn compute_crc(&self) -> u32 { let mut hasher = crc32fast::Hasher::new(); let start = std::mem::size_of::(); // start after HEAD hasher.update(&self.raw_data[start..]); @@ -230,8 +230,8 @@ impl DataChunk { }; if magic == &COMPRESSED_CHUNK_MAGIC_1_0 { - let data = zstd::block::decompress(&self.raw_data[12..], 16*1024*1024)?; - verify_raw_data(&data)?; + let data = zstd::block::decompress(&self.raw_data[12..], 16*1024*1024)?; + verify_raw_data(&data)?; } else if magic == &UNCOMPRESSED_CHUNK_MAGIC_1_0 { verify_raw_data(&self.raw_data[12..])?; }