smalot / smalot/pdfparser

Object stream parsing can exhaust PCRE JIT and read a missing capture

Open
#835 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PHP
Stars
2.7k
Forks
579
Avg merge
2m
Merged PRs (30d)
1

Description

Description

Parser::parseObject() separates an object-stream index from its body with a nested repeated regular expression, ignores the result of preg_match(), and then unconditionally reads capture 3.

On PHP 8.5 with PCRE 10.47, a synthetic object stream containing about 4,000 object/offset pairs makes the match return false with JIT stack limit exhausted. The subsequent array access raises Undefined array key 3.

The expression also eventually reaches the recursion limit with JIT disabled, so changing PCRE limits is not a durable solution.

Minimal reproduction

The existing ParserSub::exposedParseObject() test helper can reproduce this without a PDF fixture by passing an ObjStm structure containing 4,000 synthetic object-number offset pairs followed by simple null objects.

Expected behavior

Use the object-stream dictionary's required /N and /First entries to bound and separate the index, parse exactly N object/offset pairs with non-recursive logic, and reject malformed counts or offsets with a deterministic exception.

No PDF content or customer data is needed for the regression.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Parser::parseObject() and the existing ParserSub::exposedParseObject() test helper. Build the described 4,000-pair synthetic ObjStm regression and inspect the current handling of /N, /First, preg_match(), and capture 3. Done means exactly N pairs are parsed without recursive matching, while malformed counts or offsets produce a deterministic exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.