]> git.p6c8.net - jirafeau.git/commitdiff
Fix for mcrypt error, when encrypting files of size = X*1024 bytes
authorgwunderlich <gwunderlich@cocus.com>
Mon, 14 Nov 2022 14:23:21 +0000 (15:23 +0100)
committergwunderlich <gwunderlich@cocus.com>
Mon, 14 Nov 2022 14:23:21 +0000 (15:23 +0100)
lib/functions.php

index 850386b79ee6c5e6aa5e111dd8866b24d2d338c8..cfb27033d84dc8cda4a26b11a34f472937d7c35b 100644 (file)
@@ -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);

patrick-canterino.de