Skip to content

Commit b982ef9

Browse files
authored
Merge pull request #4648 from oleibman/issue4647
Drowning in Warning Messages with Corrupt Xls File
2 parents 21ef57e + ac700e6 commit b982ef9

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). Thia is a
3737
- Wrapped cells and default row height. [Issue #4584](https://github.com/PHPOffice/PhpSpreadsheet/issues/4584) [PR #4645](https://github.com/PHPOffice/PhpSpreadsheet/pull/4645)
3838
- For Php8.5, replace one of our two uses of `__wakeup` with `__unserialize`, and eliminate the other. [PR #4639](https://github.com/PHPOffice/PhpSpreadsheet/pull/4639)
3939
- Use prefix _xlfn for BASE function. [Issue #4638](https://github.com/PHPOffice/PhpSpreadsheet/issues/4638) [PR #4641](https://github.com/PHPOffice/PhpSpreadsheet/pull/4641)
40+
- Warning messages with corrupt Xls file. [Issue #4647](https://github.com/PHPOffice/PhpSpreadsheet/issues/4647) [PR #4648](https://github.com/PHPOffice/PhpSpreadsheet/pull/4648)
4041
- Additional support for union and intersection. [PR #4596](https://github.com/PHPOffice/PhpSpreadsheet/pull/4596)
4142

4243
## 2025-09-03 - 5.1.0

src/PhpSpreadsheet/Reader/XlsBase.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,20 @@ protected function decodeCodepage(string $string): string
368368
return StringHelper::convertEncoding($string, 'UTF-8', $this->codepage);
369369
}
370370

371+
protected static function confirmPos(string $data, int $pos): void
372+
{
373+
if ($pos >= strlen($data)) {
374+
throw new PhpSpreadsheetException('File appears to be corrupt'); // @codeCoverageIgnore
375+
}
376+
}
377+
371378
/**
372379
* Read 16-bit unsigned integer.
373380
*/
374381
public static function getUInt2d(string $data, int $pos): int
375382
{
383+
self::confirmPos($data, $pos + 1);
384+
376385
return ord($data[$pos]) | (ord($data[$pos + 1]) << 8);
377386
}
378387

@@ -381,6 +390,8 @@ public static function getUInt2d(string $data, int $pos): int
381390
*/
382391
public static function getInt2d(string $data, int $pos): int
383392
{
393+
self::confirmPos($data, $pos + 1);
394+
384395
return unpack('s', $data[$pos] . $data[$pos + 1])[1]; // @phpstan-ignore-line
385396
}
386397

@@ -389,6 +400,8 @@ public static function getInt2d(string $data, int $pos): int
389400
*/
390401
public static function getInt4d(string $data, int $pos): int
391402
{
403+
self::confirmPos($data, $pos + 3);
404+
392405
// FIX: represent numbers correctly on 64-bit system
393406
// http://sourceforge.net/tracker/index.php?func=detail&aid=1487372&group_id=99160&atid=623334
394407
// Changed by Andreas Rehm 2006 to ensure correct result of the <<24 block on 32 and 64bit systems

0 commit comments

Comments
 (0)