Skip to main content
Menu
Advisories

NULL pointer dereference in muhammara PDF parser when a Crypt filter DecodeParms omits the Name key

GHSA-Q3F9-HVRQ-7WWHPublished Updated GitHub

Description

The muhammara PDF library crashes with a NULL pointer dereference when it parses an encrypted PDF whose stream declares a Crypt filter but whose /DecodeParms dictionary omits the /Name key. Any application that opens an untrusted PDF with the library (for example to read, append, embed, or re-encrypt pages) can be crashed by a single crafted file, with no authentication and no user interaction. The dereference happens inside DecryptionHelper::GetCryptForStream during the initial parse of the document, so the calling application cannot intercept or recover from it.

Root Cause

When a stream uses a Crypt filter, the parser looks up the crypt filter name from the stream's /DecodeParms. The PDF specification (ISO 32000-1:2008, Table 3.4) states that when the /Name entry is absent it defaults to Identity, so a valid PDF may legitimately omit /Name. The code queries /Name and immediately calls ->GetValue() on the result without checking for NULL. When /Name is absent, QueryDictionaryObject returns NULL, the PDFObjectCastPtr wrapper holds NULL, and the subsequent ->GetValue() dereferences a NULL pointer.

packages/native-with-source/src/deps/PDFWriter/DecryptionHelper.cpp:525-526 (array /Filter path)
packages/native-with-source/src/deps/PDFWriter/DecryptionHelper.cpp:539-540 (single-name /Filter path)

PDFObjectCastPtr<PDFName> cryptFilterName(
    mParser->QueryDictionaryObject(decodeParamsItem.GetPtr(), "Name"));
return GetFilterForName(mXcrypts, cryptFilterName->GetValue());  // NULL deref when /Name absent

The sibling routine PDFParser::CreateFilterForStream (packages/native-with-source/src/deps/PDFWriter/PDFParser.cpp:2332-2338) handles the identical case correctly: it checks if (!cryptFilterName) and defaults to Identity. The decryption helper path was never given the same guard.

Impact

An unauthenticated attacker who can supply a PDF to a service that parses it with this library causes an immediate process crash (SIGSEGV in the native Node.js addon; a trap in the WebAssembly module). Because the crash occurs during StartPDFParsing, inside a parser callback, the application cannot catch it as a recoverable error, so a single request denies service for the whole process. The primitive is a read of a NULL address, so there is no information disclosure or memory write; the demonstrated impact is denial of service. PDF encryption with an empty user password is well defined, so the attacker does not need any secret to produce a validly encrypted document that reaches this path.

Proof of Concept

Dependencies: @muhammara/native-with-source (any published version, e.g. 7.1.0).
Build a small encrypted PDF whose stream object uses a Crypt filter and whose
DecodeParms dictionary is present but empty (no /Name entry), then open it.
  1. Create an encrypted PDF (RC4 V=1/R=2 or AES V=4/V=5 with an empty user password and correctly computed /O and /U values).
  2. Give one stream object /Filter /Crypt and /DecodeParms << >> (an empty dictionary; for the array form use /Filter [/Crypt] with /DecodeParms [<< >>]).
  3. Open the file with the library's reader API.
const muhammara = require('@muhammara/native-with-source');
// malicious.pdf: encrypted, empty user password, stream has /Filter /Crypt
//                and /DecodeParms << >> with no /Name entry
muhammara.createReader('malicious.pdf', new muhammara.PDFRStreamForFile('malicious.pdf'));
Process terminates with a segmentation fault (SIGSEGV) during parsing.
The reader object is never returned to the caller.

Attack Chain

  1. Exposure: A service accepts an untrusted PDF and opens it with any reader or page-manipulation API (createReader, appendPagesFromPDF, embedPDF, re-encryption, or the WebAssembly reader).
  2. Control: The attacker fully controls the PDF bytes, including the encryption dictionary and each stream's /Filter and /DecodeParms entries.
  3. Path: StartPDFParsing parses each indirect object; ParseNewObject calls NotifyIndirectObjectEnd, which unconditionally calls DecryptionHelper::OnObjectEnd (packages/native-with-source/src/deps/PDFWriter/PDFParser.cpp:2007).
  4. Guard: OnObjectEnd proceeds for a stream object when IsDecrypting() is true (the document is encrypted and the password authenticated), then calls GetCryptForStream. HasCryptFilterDefinition admits the stream because it carries a Crypt filter, but it never checks that /Name exists. The NULL check present in the sibling CreateFilterForStream is missing here.
  5. Primitive: GetCryptForStream dereferences the NULL result of the /Name lookup.
  6. Result: The process crashes (SIGSEGV / Wasm trap), denying service.

Bypass Evidence

The only relevant protections on this path are HasCryptFilterDefinition and the /DecodeParms presence checks. HasCryptFilterDefinition verifies only that a Crypt filter is present and does not examine /Name. The /DecodeParms null checks at lines 518-523 and 536-537 are satisfied when /DecodeParms is present but empty, so both the array and single-name branches reach the unguarded /Name dereference. The strongest counter-argument considered was that the sibling CreateFilterForStream defaults a missing /Name to Identity; inspection confirms that guard exists only in CreateFilterForStream (PDFParser.cpp:2332-2338) and not in GetCryptForStream, which proves the crash rather than refuting it. A second counter-argument, that a parser extender might intercept the object, fails because the OnObjectEnd call to the decryption helper is unconditional and runs regardless of any extender.

Affected Versions

  • Ecosystem: npm
  • Package: @muhammara/native-with-source
  • Confirmed affected range: <= 7.1.0
  • Latest release checked: 7.1.0 (npm registry)
  • Fix status: not fixed

The companion package @muhammara/wasm ships the same vendored parser and is affected across all its published versions (<= 1.1.0, latest 1.1.0). The vulnerable code has been present since the first commit of this repository, and no released version contains a fix.

Suggested Fix

Guard the /Name lookup before dereferencing it, mirroring the existing logic in CreateFilterForStream: when QueryDictionaryObject(..., "Name") returns NULL, treat the crypt filter name as Identity instead of calling ->GetValue(). Apply the fix to both branches of GetCryptForStream (the array /Filter path and the single-name /Filter path), since each performs the same unguarded dereference.

---

Reported by zx.

Affected versions

References

GitHub · julianhille/MuhammaraJS