From 2445d1cdb438f1a05a939f140579f22c139991bd Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Fri, 10 Jan 2025 17:08:34 +0100 Subject: [PATCH] allow encrypting empty chunks related to f07ef0e --- .../org/cryptomator/cryptolib/v3/FileContentCryptorImpl.java | 2 +- .../cryptomator/cryptolib/v2/FileContentCryptorImplTest.java | 4 ++-- .../cryptomator/cryptolib/v3/FileContentCryptorImplTest.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/cryptomator/cryptolib/v3/FileContentCryptorImpl.java b/src/main/java/org/cryptomator/cryptolib/v3/FileContentCryptorImpl.java index f301d5e..6a8c823 100644 --- a/src/main/java/org/cryptomator/cryptolib/v3/FileContentCryptorImpl.java +++ b/src/main/java/org/cryptomator/cryptolib/v3/FileContentCryptorImpl.java @@ -55,7 +55,7 @@ public ByteBuffer encryptChunk(ByteBuffer cleartextChunk, long chunkNumber, File @Override public void encryptChunk(ByteBuffer cleartextChunk, ByteBuffer ciphertextChunk, long chunkNumber, FileHeader header) { - if (cleartextChunk.remaining() <= 0 || cleartextChunk.remaining() > PAYLOAD_SIZE) { + if (cleartextChunk.remaining() < 0 || cleartextChunk.remaining() > PAYLOAD_SIZE) { throw new IllegalArgumentException("Invalid cleartext chunk size: " + cleartextChunk.remaining() + ", expected range [1, " + PAYLOAD_SIZE + "]"); } if (ciphertextChunk.remaining() < CHUNK_SIZE) { diff --git a/src/test/java/org/cryptomator/cryptolib/v2/FileContentCryptorImplTest.java b/src/test/java/org/cryptomator/cryptolib/v2/FileContentCryptorImplTest.java index e350fbd..592481d 100644 --- a/src/test/java/org/cryptomator/cryptolib/v2/FileContentCryptorImplTest.java +++ b/src/test/java/org/cryptomator/cryptolib/v2/FileContentCryptorImplTest.java @@ -78,7 +78,7 @@ public class Encryption { @DisplayName("encrypt chunk with invalid size") @ParameterizedTest(name = "cleartext size: {0}") - @ValueSource(ints = {0, org.cryptomator.cryptolib.v2.Constants.PAYLOAD_SIZE + 1}) + @ValueSource(ints = {0, Constants.PAYLOAD_SIZE + 1}) public void testEncryptChunkOfInvalidSize(int size) { ByteBuffer cleartext = ByteBuffer.allocate(size); @@ -147,7 +147,7 @@ public class Decryption { @DisplayName("decrypt chunk with invalid size") @ParameterizedTest(name = "ciphertext size: {0}") - @ValueSource(ints = {0, Constants.GCM_NONCE_SIZE + Constants.GCM_TAG_SIZE - 1, org.cryptomator.cryptolib.v2.Constants.CHUNK_SIZE + 1}) + @ValueSource(ints = {0, Constants.GCM_NONCE_SIZE + Constants.GCM_TAG_SIZE - 1, Constants.CHUNK_SIZE + 1}) public void testDecryptChunkOfInvalidSize(int size) { ByteBuffer ciphertext = ByteBuffer.allocate(size); diff --git a/src/test/java/org/cryptomator/cryptolib/v3/FileContentCryptorImplTest.java b/src/test/java/org/cryptomator/cryptolib/v3/FileContentCryptorImplTest.java index d60d58f..6968d2e 100644 --- a/src/test/java/org/cryptomator/cryptolib/v3/FileContentCryptorImplTest.java +++ b/src/test/java/org/cryptomator/cryptolib/v3/FileContentCryptorImplTest.java @@ -93,7 +93,7 @@ public class Encryption { @DisplayName("encrypt chunk with invalid size") @ParameterizedTest(name = "cleartext size: {0}") - @ValueSource(ints = {0, Constants.PAYLOAD_SIZE + 1}) + @ValueSource(ints = {Constants.PAYLOAD_SIZE + 1}) public void testEncryptChunkOfInvalidSize(int size) { ByteBuffer cleartext = ByteBuffer.allocate(size);