From ab5ad2099860bd841003a973104dc819c74357e6 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 29 May 2024 12:40:35 +0200 Subject: [server] CoW: Fix race condition generating invalid hashes It's not too f'n bright to use a shared buffer in a multi-threaded environment.... --- .../src/main/java/org/openslx/bwlp/sat/fileserv/cow/CowFinalizer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/cow/CowFinalizer.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/cow/CowFinalizer.java index 9e4a7256..67f38634 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/cow/CowFinalizer.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/cow/CowFinalizer.java @@ -77,7 +77,6 @@ public class CowFinalizer { } private void calculateHashes() throws IOException { - byte[] buffer = new byte[FileChunk.CHUNK_SIZE]; HashChecker hc = IncomingTransferBase.getHashChecker(); if (hc == null) { LOGGER.info("No hash checker, skipping..."); @@ -96,7 +95,8 @@ public class CowFinalizer { } }; for (FileChunk chunk : chunks.getAll()) { - file.readFully(buffer, 0, chunk.range.getLength()); + byte[] buffer = new byte[chunk.range.getLength()]; + file.readFully(buffer); hc.queue(chunk, buffer, cb, HashChecker.BLOCKING | HashChecker.CALC_CRC32 | HashChecker.CALC_SHA1 | HashChecker.NO_SLOW_WARN); } -- cgit v1.2.3-55-g7522