From ed741437c07a086abecc2cb0699536f475af642b Mon Sep 17 00:00:00 2001 From: Hideki Miyazaki Date: Fri, 27 Mar 2026 14:19:58 +0900 Subject: [PATCH 1/3] fix read of exctly MAX_LEN bytes treated as error --- src/crypto/clu_decrypt.c | 2 +- tests/encrypt/enc-test.sh | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/crypto/clu_decrypt.c b/src/crypto/clu_decrypt.c index 5a5aa0f4..997d85ed 100644 --- a/src/crypto/clu_decrypt.c +++ b/src/crypto/clu_decrypt.c @@ -156,7 +156,7 @@ int wolfCLU_decrypt(int alg, char* mode, byte* pwdKey, byte* key, int size, } else { ret = (int)XFREAD(input, 1, MAX_LEN, inFile); - if ((ret > 0 && ret != MAX_LEN) || feof(inFile)) { + if (ret > 0) { tempMax = ret; ret = 0; /* success */ } diff --git a/tests/encrypt/enc-test.sh b/tests/encrypt/enc-test.sh index 31b7754f..ae9d355f 100755 --- a/tests/encrypt/enc-test.sh +++ b/tests/encrypt/enc-test.sh @@ -185,5 +185,28 @@ fi rm -f test-dec.der rm -f test-enc.der +# camellia: decrypt file larger than MAX_LEN (non-EVP path) +if grep -q "HAVE_CAMELLIA" wolfssl/wolfssl/options.h 2>/dev/null; then + dd if=/dev/urandom bs=2048 count=1 of=test_maxlen_camellia.bin 2>/dev/null + ./wolfssl encrypt camellia-cbc-128 -pwd testpwd \ + -in test_maxlen_camellia.bin -out test_maxlen_camellia.enc + if [ $? != 0 ]; then + echo "failed to encrypt in MAX_LEN boundary test" + exit 99 + fi + ./wolfssl decrypt camellia-cbc-128 \ + -in test_maxlen_camellia.enc -out test_maxlen_camellia.dec -pwd testpwd + if [ $? != 0 ]; then + echo "failed to decrypt in MAX_LEN boundary test" + exit 99 + fi + diff test_maxlen_camellia.bin test_maxlen_camellia.dec &> /dev/null + if [ $? != 0 ]; then + echo "MAX_LEN boundary: decrypted file does not match original" + exit 99 + fi + rm -f test_maxlen_camellia.bin test_maxlen_camellia.enc test_maxlen_camellia.dec +fi + echo "Done" exit 0 From 86be75d792788c6223797076919be5ed2f8761e6 Mon Sep 17 00:00:00 2001 From: Hideki Miyazaki Date: Fri, 27 Mar 2026 14:35:32 +0900 Subject: [PATCH 2/3] addressed copilot comments --- src/crypto/clu_decrypt.c | 7 ++++++- tests/encrypt/enc-test.sh | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/crypto/clu_decrypt.c b/src/crypto/clu_decrypt.c index 997d85ed..85d29395 100644 --- a/src/crypto/clu_decrypt.c +++ b/src/crypto/clu_decrypt.c @@ -161,7 +161,12 @@ int wolfCLU_decrypt(int alg, char* mode, byte* pwdKey, byte* key, int size, ret = 0; /* success */ } else { - wolfCLU_LogError("Input file does not exist."); + if (feof(inFile)) { + wolfCLU_LogError("Unexpected end of file."); + } + else { + wolfCLU_LogError("File read error."); + } ret = FREAD_ERROR; } } diff --git a/tests/encrypt/enc-test.sh b/tests/encrypt/enc-test.sh index ae9d355f..6a7b015a 100755 --- a/tests/encrypt/enc-test.sh +++ b/tests/encrypt/enc-test.sh @@ -185,7 +185,7 @@ fi rm -f test-dec.der rm -f test-enc.der -# camellia: decrypt file larger than MAX_LEN (non-EVP path) +# camellia: decrypt file of exactly MAX_LEN bytes (non-EVP path) if grep -q "HAVE_CAMELLIA" wolfssl/wolfssl/options.h 2>/dev/null; then dd if=/dev/urandom bs=2048 count=1 of=test_maxlen_camellia.bin 2>/dev/null ./wolfssl encrypt camellia-cbc-128 -pwd testpwd \ From 7f916831dd584713124af0401054d7f3d9c35926 Mon Sep 17 00:00:00 2001 From: Hideki Miyazaki Date: Thu, 9 Apr 2026 09:59:45 +0900 Subject: [PATCH 3/3] Addressed Copilot review comments --- tests/encrypt/enc-test.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/encrypt/enc-test.sh b/tests/encrypt/enc-test.sh index 6a7b015a..13631cf0 100755 --- a/tests/encrypt/enc-test.sh +++ b/tests/encrypt/enc-test.sh @@ -185,7 +185,8 @@ fi rm -f test-dec.der rm -f test-enc.der -# camellia: decrypt file of exactly MAX_LEN bytes (non-EVP path) +# camellia: decrypt file whose size is a multiple of MAX_LEN (2 x 1024 bytes) +# to ensure the exact-boundary read case is covered (non-EVP path) if grep -q "HAVE_CAMELLIA" wolfssl/wolfssl/options.h 2>/dev/null; then dd if=/dev/urandom bs=2048 count=1 of=test_maxlen_camellia.bin 2>/dev/null ./wolfssl encrypt camellia-cbc-128 -pwd testpwd \