From 41f33f9c1dac5381412bcab57c971fd08d1d8613 Mon Sep 17 00:00:00 2001 From: gwunderlich Date: Mon, 14 Nov 2022 15:23:21 +0100 Subject: [PATCH] Fix for mcrypt error, when encrypting files of size = X*1024 bytes --- lib/functions.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/functions.php b/lib/functions.php index 850386b..cfb2703 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -1205,10 +1205,13 @@ function jirafeau_encrypt_file($fp_src, $fp_dst) /* Crypt file. */ $r = fopen($fp_src, 'r'); $w = fopen($fp_dst, 'c'); - while (!feof($r)) { - $enc = mcrypt_generic($m, fread($r, 1024)); - if (fwrite($w, $enc) === false) { - return ''; + while (!feof($r)) { + $to_enc = fread($r, 1024); + if (strlen($to_enc) > 0) { + $enc = mcrypt_generic($m, $to_enc); + if (fwrite($w, $enc) === false) { + return ''; + } } } fclose($r); -- 2.34.1