Correctly fail if file is too short (bug #1574340).

This commit is contained in:
Michal Čihař
2006-10-10 13:04:24 +00:00
parent 8096c576e0
commit 5bf8f4aba7
2 changed files with 6 additions and 3 deletions

View File

@@ -7,6 +7,8 @@ $Source$
2006-10-10 Michal Čihař <michal@cihar.com> 2006-10-10 Michal Čihař <michal@cihar.com>
* lang/german: Fix typo (translation #1467138). * lang/german: Fix typo (translation #1467138).
* libraries/import.lib.php: Correctly fail if file is too short (bug
#1574340).
2006-10-09 Michal Čihař <michal@cihar.com> 2006-10-09 Michal Čihař <michal@cihar.com>
* lang/german: Fix typo (translation #1570611). * lang/german: Fix typo (translation #1570611).

View File

@@ -45,14 +45,15 @@ function PMA_detectCompression($filepath)
return FALSE; return FALSE;
} }
$test = fread($file, 4); $test = fread($file, 4);
$len = strlen($test);
fclose($file); 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'; return 'application/gzip';
} }
if (substr($test, 0, 3) == 'BZh') { if ($len >= 3 && substr($test, 0, 3) == 'BZh') {
return 'application/bzip2'; return 'application/bzip2';
} }
if ($test == "PK\003\004") { if ($len >= 4 && $test == "PK\003\004") {
return 'application/zip'; return 'application/zip';
} }
return 'none'; return 'none';