Skip to main content
Menu
Advisories

PNG predictor returns memory it never wrote for rows with an unknown filter type, disclosing data across documents

GHSA-7GX7-F7MG-M8W6Published Updated GitHub

Description

A FlateDecode or LZWDecode stream with a PNG predictor (/Predictor 10–15) whose rows carry an unknown PNG filter type (a row tag of 5 or more) is decoded without writing the output for those rows: the decoder returns whatever the caller's buffer held before. In the WebAssembly package that is leftover linear memory, including text of documents processed earlier in the same instance; in the native package it is heap memory, including heap addresses. Any application that extracts text from, or decodes streams of, untrusted PDFs can disclose memory this way, and the Wasm Recipe writes it into its output PDF.

Root Cause

InputPredictorPNGOptimumStream decodes each byte in DecodeNextByte() with a switch over the row's filter type that handles only types 0–4 and has no default. For any other type the decoded byte is never assigned, so the caller's buffer is returned unchanged and also kept as the next row's "up" values.

packages/native-with-source/src/deps/PDFWriter/InputPredictorPNGOptimumStream.cpp:121-150   DecodeNextByte: switch over filter types 0-4, no default

(Line numbers refer to the 7.2.3 source.)

Impact

  • Wasm: after one document was processed, a crafted PDF read in the same instance returned that document's text through extractPageText() and startReadingFromStream(), and Recipe#replaceText() on a crafted PDF wrote about 22 KB of stale linear memory into the output's content stream. Confirmed on 1.2.3.
  • Native: the content parser (extractPageText(), extractPageContentItems(), startReadingObjectsFromStream(s)) returns uninitialised heap memory, pointer values included; valgrind traces the extracted text to uninitialised heap allocations. startReadingFromStream().read() returns zeros there. Confirmed on 7.2.3.

Proof of Concept

A page content stream << /Filter /FlateDecode /DecodeParms << /Predictor 12 /Columns 4 >> >> whose decompressed rows start with the tag byte 7, read with extractPageText() after another document has been processed in the same Wasm instance.

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 @muhammara/native-with-source and @muhammara/native 7.2.4 and @muhammara/wasm 1.2.4.

A row with an unknown PNG filter type is now decoded as type 0 (no prediction), as xpdf does, so every output byte is written.

Workarounds

Use a fresh Wasm instance per document to limit cross-document disclosure, or do not decode streams of untrusted PDFs with affected versions.

References

  • Related: GHSA-mvmf-5vvf-74m7 and GHSA-rw6g-24h2-52ch (other decoders returning memory they never wrote or read out of bounds).
  • The same code is in upstream galkahana/PDF-Writer.

---

Found by the project's scheduled WebAssembly fuzzing and the follow-up review of its results.

Affected versions

References

GitHub · julianhille/MuhammaraJS