From 5bf8f4aba76fd8899435edffc69fb40ddc4320d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 10 Oct 2006 13:04:24 +0000 Subject: [PATCH] Correctly fail if file is too short (bug #1574340). --- ChangeLog | 2 ++ libraries/import.lib.php | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index ebbc4ed43..5928698a7 100755 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,8 @@ $Source$ 2006-10-10 Michal Čihař * lang/german: Fix typo (translation #1467138). + * libraries/import.lib.php: Correctly fail if file is too short (bug + #1574340). 2006-10-09 Michal Čihař * lang/german: Fix typo (translation #1570611). diff --git a/libraries/import.lib.php b/libraries/import.lib.php index bf5414f38..778ae5c14 100644 --- a/libraries/import.lib.php +++ b/libraries/import.lib.php @@ -45,14 +45,15 @@ function PMA_detectCompression($filepath) return FALSE; } $test = fread($file, 4); + $len = strlen($test); fclose($file); - if ($test[0] == chr(31) && $test[1] == chr(139)) { + if ($len >= 2 && $test[0] == chr(31) && $test[1] == chr(139)) { return 'application/gzip'; } - if (substr($test, 0, 3) == 'BZh') { + if ($len >= 3 && substr($test, 0, 3) == 'BZh') { return 'application/bzip2'; } - if ($test == "PK\003\004") { + if ($len >= 4 && $test == "PK\003\004") { return 'application/zip'; } return 'none';