Skip to content

Commit f7518da

Browse files
anton-harveyPowerKiKi
authored andcommitted
Return false if the zip entry could not be located
Previously the function did not check whether the return value of `ZipArchive::locateName` was `false`. And when it was, it was passed straight into `ZipArchive::getFromIndex`, which casts it to an integer, resulting in it incorrectly retrieving the entry at index `0`. Fixes #262 Closes #268
1 parent 8183c71 commit f7518da

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2424
- Control characters in cell values are automatically escaped - [#212](https://github.com/PHPOffice/PhpSpreadsheet/issues/212)
2525
- Prevent color changing when copy/pasting xls files written by PhpSpreadsheet to another file - @al-lala [#218](https://github.com/PHPOffice/PhpSpreadsheet/issues/218)
2626
- Add cell reference automatic when there is no cell reference('r' attribute) in Xlsx file. - @GreatHumorist [#225](https://github.com/PHPOffice/PhpSpreadsheet/pull/225) Refer to [issue#201](https://github.com/PHPOffice/PhpSpreadsheet/issues/201)
27+
- `Reader\Xlsx::getFromZipArchive()` function return false if the zip entry could not be located. - @anton-harvey [#268](https://github.com/PHPOffice/PhpSpreadsheet/pull/268)
2728

2829
### BREAKING CHANGE
2930

src/PhpSpreadsheet/Reader/Xlsx.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,13 +308,9 @@ private function getFromZipArchive(ZipArchive $archive, $fileName = '')
308308
// so we need to load case-insensitively from the zip file
309309

310310
// Apache POI fixes
311-
$contents = $archive->getFromIndex(
312-
$archive->locateName($fileName, ZipArchive::FL_NOCASE)
313-
);
311+
$contents = $archive->getFromName($fileName, 0, ZipArchive::FL_NOCASE);
314312
if ($contents === false) {
315-
$contents = $archive->getFromIndex(
316-
$archive->locateName(substr($fileName, 1), ZipArchive::FL_NOCASE)
317-
);
313+
$contents = $archive->getFromName(substr($fileName, 1), 0, ZipArchive::FL_NOCASE);
318314
}
319315

320316
return $contents;

0 commit comments

Comments
 (0)