# GHSA-PVFX-H82V-PXJJ: Crafted cross-reference data exhausts memory or CPU when a PDF is opened

- Database: GitHub
- Severity: high (stated by ghsa, no CVSS score)
- Published: 2026-11-18
- Modified: 2026-11-18

## Affected versions

- @muhammara/native-with-source (npm): through 7.2.3
- @muhammara/native (npm): through 7.2.3
- @muhammara/wasm (npm): through 1.2.3

## Description

## Summary

Cross-reference data in a PDF of a few hundred bytes can make parsing use gigabytes of memory or many seconds of CPU: a section that starts at a huge object number grows the parser's cross-reference table to that size, a chain of incremental updates or an xref stream that repeats an entry range is walked again and again, and an object stream whose header cannot be parsed is parsed again on every access. A PDF of less than 300 bytes makes `createReader()` abort the native process with an uncaught `std::bad_alloc`, or exhaust memory, and aborts the WebAssembly module.

## Root Cause

`PDFParser::ExtendXrefToSize()` (`packages/native-with-source/src/deps/PDFWriter/PDFParser.cpp`, vendored PDF-Writer) resizes the cross-reference table to whatever size a section asks for, up to `MAX_XREF_SIZE` (9,999,999,999 entries; 24 bytes each on native, 16 on Wasm). It is called with the start of each classic cross-reference subsection and with each `/Index` start of a cross-reference stream, so a section that starts at a huge object number allocates every entry below it, even though the file defines none of them. The `/Prev` chain, the cross-reference stream entries and the object-stream headers were not bounded in total either, so repeating them multiplies the work.

```text
packages/native-with-source/src/deps/PDFWriter/PDFParser.cpp:53     #define MAX_XREF_SIZE 9999999999LL
packages/native-with-source/src/deps/PDFWriter/PDFParser.cpp:577    ExtendXrefToSize()
packages/native-with-source/src/deps/PDFWriter/PDFParser.cpp:702    classic subsection start
packages/native-with-source/src/deps/PDFWriter/PDFParser.cpp:1808   cross-reference stream /Index start
```

(Line numbers refer to the 7.2.3 source.)

The same code is in upstream galkahana/PDF-Writer.

## Impact

Denial of service for any application that opens untrusted PDFs: `createReader()` alone is enough, as is every API that parses a PDF (`createWriterToModify()`, `appendPDFPagesFromPDF()`, `createPDFCopyingContext()`, Recipe).

- Native (`@muhammara/native`, `@muhammara/native-with-source`): a 288-byte PDF aborts the process ("terminate called after throwing an instance of 'std::bad_alloc'"); a 284-byte PDF whose section starts at object 50,000,000 makes the process use 1.2 GB. Confirmed on 7.2.3.
- Wasm (`@muhammara/wasm`): the 284-byte PDF aborts the module with `RuntimeError: Aborted()`. Confirmed on 1.2.3.
- Slow parsing: a file of about 1 KB whose cross-reference stream repeats a large `/Index` range with zero-byte-field entries takes seconds to open, growing linearly with the repetitions; a 34 KB file whose object stream header is broken takes minutes to append. Confirmed on 7.2.3.

The table size also bounds the object-stream `/N` check and the page-tree `/Count` check, so a large table raises those bounds too.

## Proof of Concept

A cross-reference stream `<< /Type /XRef /Size 9999999991 /Index [0 4 9999999990 1] /W [1 4 1] … >>` (or a classic `xref` subsection header `9999999990 1`), opened with `createReader(path)`.

## Affected Versions

- **Ecosystem:** `npm`
- **Packages:** `@muhammara/native-with-source` and `@muhammara/native` `<= 7.2.3`; `@muhammara/wasm` `<= 1.2.3`
- **Patched versions:** `@muhammara/native-with-source` and `@muhammara/native` `7.2.4`; `@muhammara/wasm` `1.2.4`
- **Confirmed on:** native `7.2.3`, Wasm `1.2.3`

## Patches

Fixed in `7.2.4` / `1.2.4`:

- The cross-reference table is limited to 8,388,608 entries, which covers the PDF 1.7 limit of 8,388,607 indirect objects. A file that needs more fails to open.
- The total size of all tables in a `/Prev` chain is limited to 16 times that bound, and the entries read from cross-reference streams are limited the same way, so repeating them fails instead of running for minutes.
- The headers of all object streams together may list at most twice the table size plus 1,048,576 entries. Valid incremental updates that rewrite objects into new object streams stay well under this.
- An object stream whose header cannot be parsed is remembered as failed, so its objects are not parsed again on every access.
- The registry of modified objects is a deque, so modifying a file at the limit no longer aborts Wasm.

Residual cost: a file that stays within these limits can still take up to about 4 seconds of CPU natively and 6 seconds on Wasm to parse. On Wasm, opening two object streams of maximum size in one modify operation can still exhaust the 512 MiB of memory; `dispose()` on the Recipe releases it.

## Workarounds

None for untrusted input short of upgrading; running parsing in a separate, memory-limited process contains the impact.

## References

- Related: public issue #917 (object-stream `/N` bound by the cross-reference table size).
- The same code is in upstream galkahana/PDF-Writer.

---

Found during the security review of the 7.2.4 release.

## References

- https://github.com/julianhille/MuhammaraJS/security/advisories/GHSA-pvfx-h82v-pxjj

Page: https://cve.now/GHSA-PVFX-H82V-PXJJ

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
