Skip to content

Commit 747ccd1

Browse files
authored
Merge pull request #4514 from oleibman/parsehuge4
Allow Xlsx Reader to Specify ParseHuge Master
2 parents d25979f + be45c88 commit 747ccd1

File tree

2 files changed

+42
-10
lines changed

2 files changed

+42
-10
lines changed

CHANGELOG.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com)
66
and this project adheres to [Semantic Versioning](https://semver.org).
77

8-
## TBD - 4.4.0
8+
## TBD - 4.5.0
99

1010
### Added
1111

12-
- VSTACK and HSTACK. [Issue #4485](https://github.com/PHPOffice/PhpSpreadsheet/issues/4485) [PR #4492](https://github.com/PHPOffice/PhpSpreadsheet/pull/4492)
13-
- TOCOL and TOROW. [PR #4493](https://github.com/PHPOffice/PhpSpreadsheet/pull/4493)
14-
- Support Current Office Theme. [PR #4500](https://github.com/PHPOffice/PhpSpreadsheet/pull/4500)
12+
- Nothing yet.
1513

1614
### Removed
1715

@@ -27,6 +25,22 @@ and this project adheres to [Semantic Versioning](https://semver.org).
2725

2826
### Deprecated
2927

28+
- Nothing yet.
29+
30+
### Fixed
31+
32+
- Nothing yet.
33+
34+
## 2025-06-22 - 4.4.0
35+
36+
### Added
37+
38+
- VSTACK and HSTACK. [Issue #4485](https://github.com/PHPOffice/PhpSpreadsheet/issues/4485) [PR #4492](https://github.com/PHPOffice/PhpSpreadsheet/pull/4492)
39+
- TOCOL and TOROW. [PR #4493](https://github.com/PHPOffice/PhpSpreadsheet/pull/4493)
40+
- Support Current Office Theme. [PR #4500](https://github.com/PHPOffice/PhpSpreadsheet/pull/4500)
41+
42+
### Deprecated
43+
3044
- Theme constants COLOR_SCHEME_2013_PLUS_NAME (use COLOR_SCHEME_2013_2022_NAME) and COLOR_SCHEME_2013_PLUS (use COLOR_SCHEME_2013_2022).
3145

3246
### Fixed
@@ -36,6 +50,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
3650
- Allow Xlsx Reader/Writer to support Font Charset. [Issue #2760](https://github.com/PHPOffice/PhpSpreadsheet/issues/2760) [PR #4501](https://github.com/PHPOffice/PhpSpreadsheet/pull/4501)
3751
- AutoColor for LibreOffice Dark Mode [Discussion 4502](https://github.com/PHPOffice/PhpSpreadsheet/discussions/4502) [PR #4503](https://github.com/PHPOffice/PhpSpreadsheet/pull/4503)
3852
- Xlsx Style Writer Minor Refactoring. [PR #4508](https://github.com/PHPOffice/PhpSpreadsheet/pull/4508)
53+
- Allow Xlsx Reader to Specify ParseHuge. [Issue #4260](https://github.com/PHPOffice/PhpSpreadsheet/issues/4260) [PR #4515](https://github.com/PHPOffice/PhpSpreadsheet/pull/4515)
3954

4055
## 2025-05-26 - 4.3.1
4156

src/PhpSpreadsheet/Reader/Xlsx.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ class Xlsx extends BaseReader
6161
/** @var SharedFormula[] */
6262
private array $sharedFormulae = [];
6363

64+
private bool $parseHuge = false;
65+
66+
/**
67+
* Allow use of LIBXML_PARSEHUGE.
68+
* This option can lead to memory leaks and failures,
69+
* and is not recommended. But some very large spreadsheets
70+
* seem to require it.
71+
*/
72+
public function setParseHuge(bool $parseHuge): void
73+
{
74+
$this->parseHuge = $parseHuge;
75+
}
76+
6477
/**
6578
* Create a new Xlsx Reader instance.
6679
*/
@@ -124,8 +137,8 @@ private function loadZip(string $filename, string $ns = '', bool $replaceUnclose
124137
}
125138
$rels = @simplexml_load_string(
126139
$this->getSecurityScannerOrThrow()->scan($contents),
127-
'SimpleXMLElement',
128-
0,
140+
SimpleXMLElement::class,
141+
$this->parseHuge ? LIBXML_PARSEHUGE : 0,
129142
$ns
130143
);
131144

@@ -139,8 +152,8 @@ private function loadZipNonamespace(string $filename, string $ns): SimpleXMLElem
139152
$contents = $this->getFromZipArchive($this->zip, $filename);
140153
$rels = simplexml_load_string(
141154
$this->getSecurityScannerOrThrow()->scan($contents),
142-
'SimpleXMLElement',
143-
0,
155+
SimpleXMLElement::class,
156+
$this->parseHuge ? LIBXML_PARSEHUGE : 0,
144157
($ns === '' ? $ns : '')
145158
);
146159

@@ -259,7 +272,9 @@ public function listWorksheetInfo(string $filename): array
259272
$this->zip,
260273
$fileWorksheetPath
261274
)
262-
)
275+
),
276+
null,
277+
$this->parseHuge ? LIBXML_PARSEHUGE : 0
263278
);
264279
$xml->setParserProperty(2, true);
265280

@@ -2047,7 +2062,9 @@ private function readRibbon(Spreadsheet $excel, string $customUITarget, ZipArchi
20472062
// exists and not empty if the ribbon have some pictures (other than internal MSO)
20482063
$UIRels = simplexml_load_string(
20492064
$this->getSecurityScannerOrThrow()
2050-
->scan($dataRels)
2065+
->scan($dataRels),
2066+
SimpleXMLElement::class,
2067+
$this->parseHuge ? LIBXML_PARSEHUGE : 0
20512068
);
20522069
if (false !== $UIRels) {
20532070
// we need to save id and target to avoid parsing customUI.xml and "guess" if it's a pseudo callback who load the image

0 commit comments

Comments
 (0)