From d8529b7477be1783bf47d5ec9c1bfe98b0bf4f07 Mon Sep 17 00:00:00 2001 From: Jerome Jutteau Date: Wed, 4 Dec 2019 23:14:17 +0100 Subject: [PATCH] [FIX] Better error handling with md5_outside Signed-off-by: Jerome Jutteau --- lib/functions.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/functions.php b/lib/functions.php index 4e22796..5a5316c 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -343,22 +343,30 @@ function jirafeau_hash_file($method, $file_path) */ function jirafeau_md5_outside($file_path) { - $size = filesize($file_path); - if ($size === false) { - $size = 0; - } + $out = false; $handle = fopen($file_path, "r"); if ($handle === false) { return false; } + $size = filesize($file_path); + if ($size === false) { + goto err; + } $first = fread($handle, 64); if ($first === false) { - return false; + goto err; + } + if (fseek($handle, $size < 64 ? 0 : $size - 64) == -1) { + goto err; } - fseek($handle, $size < 64 ? 0 : $size - 64); $last = fread($handle, 64); + if ($last === false) { + goto err; + } + $out = md5($first . $last . $size); + err: fclose($handle); - return md5($first . $last . $size); + return $out; } /** -- 2.34.1