From: gwunderlich Date: Mon, 14 Nov 2022 14:23:21 +0000 (+0100) Subject: Fix for mcrypt error, when encrypting files of size = X*1024 bytes X-Git-Url: https://git.p6c8.net/jirafeau_mojo42.git/commitdiff_plain/41f33f9c1dac5381412bcab57c971fd08d1d8613?ds=inline Fix for mcrypt error, when encrypting files of size = X*1024 bytes --- 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);