diff --git a/pom.xml b/pom.xml index 6a07e495..c708f3dd 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 org.cryptomator cryptofs - 2.6.4 + 2.6.5 Cryptomator Crypto Filesystem This library provides the Java filesystem provider used by Cryptomator. https://github.com/cryptomator/cryptofs @@ -21,7 +21,7 @@ 2.1.2 4.3.0 2.44.2 - 31.1-jre + 32.0.0-jre 3.1.4 2.0.3 diff --git a/src/main/java/org/cryptomator/cryptofs/fh/ChunkCache.java b/src/main/java/org/cryptomator/cryptofs/fh/ChunkCache.java index 9e8e2a20..ee5eb56f 100644 --- a/src/main/java/org/cryptomator/cryptofs/fh/ChunkCache.java +++ b/src/main/java/org/cryptomator/cryptofs/fh/ChunkCache.java @@ -86,9 +86,10 @@ public Chunk putChunk(long chunkIndex, ByteBuffer chunkData) throws IllegalArgum if (chunk == null) { chunk = new Chunk(chunkData, true, () -> releaseChunk(chunkIndex)); } else { - var dst = chunk.data().duplicate().clear(); + var dst = chunk.data().clear(); Preconditions.checkArgument(chunkData.remaining() == dst.remaining()); - dst.put(chunkData); + dst.put(chunkData) // + .flip(); chunk.dirty().set(true); } chunk.currentAccesses().incrementAndGet(); diff --git a/src/test/java/org/cryptomator/cryptofs/CryptoFileChannelWriteReadIntegrationTest.java b/src/test/java/org/cryptomator/cryptofs/CryptoFileChannelWriteReadIntegrationTest.java index 02bda852..2bcbaf42 100644 --- a/src/test/java/org/cryptomator/cryptofs/CryptoFileChannelWriteReadIntegrationTest.java +++ b/src/test/java/org/cryptomator/cryptofs/CryptoFileChannelWriteReadIntegrationTest.java @@ -53,7 +53,6 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.IntStream; import java.util.stream.Stream; @@ -175,6 +174,25 @@ public void afterEach() throws IOException { Files.deleteIfExists(file); } + //https://github.com/cryptomator/cryptofs/issues/173 + @Test + @DisplayName("First incomplete, then completely filled chunks are stored completely") + public void testFullChunksAreSavedCompletely() throws IOException { + int halfAChunk = 16_384; //half of cleartext chunk size + try (var writer = FileChannel.open(file, CREATE, WRITE)) { + writer.write(ByteBuffer.allocate(3 * halfAChunk), 0); //fill chunk 0, half fill chunk 1 + writer.write(ByteBuffer.allocate(5 * halfAChunk), 0); //fill chunks 0 and 1, half fill chunk 2 + } + + try (var reader = FileChannel.open(file, CREATE, READ)) { + Assertions.assertAll(() -> reader.read(ByteBuffer.allocate(2 * halfAChunk), 0), //read chunk 0 + () -> reader.read(ByteBuffer.allocate(2 * halfAChunk), 2 * halfAChunk), //read chunk 1 + () -> reader.read(ByteBuffer.allocate(halfAChunk), 4 * halfAChunk) //read chunk 2 + ); + } + + } + @Test public void testLockEmptyChannel() throws IOException { try (FileChannel ch = FileChannel.open(file, CREATE, WRITE)) { diff --git a/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemsTest.java b/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemsTest.java index 26dcf5e6..df120142 100644 --- a/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemsTest.java +++ b/src/test/java/org/cryptomator/cryptofs/CryptoFileSystemsTest.java @@ -70,9 +70,9 @@ public class CryptoFileSystemsTest { @BeforeEach public void setup() throws IOException, MasterkeyLoadingFailedException { vaultConficClass = Mockito.mockStatic(VaultConfig.class); - filesClass = Mockito.mockStatic(Files.class); cryptorProviderClass = Mockito.mockStatic(CryptorProvider.class); backupHelperClass = Mockito.mockStatic(BackupHelper.class); + filesClass = Mockito.mockStatic(Files.class); when(pathToVault.normalize()).thenReturn(normalizedPathToVault); when(normalizedPathToVault.resolve("vault.cryptomator")).thenReturn(configFilePath); diff --git a/suppression.xml b/suppression.xml index a7fe7425..ebb877b8 100644 --- a/suppression.xml +++ b/suppression.xml @@ -9,12 +9,4 @@ cpe:/a:cryptomator:cryptomator CVE-2022-25366 - - - ^pkg:maven/com\.google\.guava/guava@.*$ - CVE-2020-8908 - CVE-2020-8908 - \ No newline at end of file