Skip to content

Bound the work and recursion depth of PostScript Type 4 compilation - #22231

Merged
calixteman merged 2 commits into
mozilla:masterfrom
calixteman:ps-tree-work-budget
Oct 18, 2026
Merged

calixteman merged 2 commits into
mozilla:masterfrom
calixteman:ps-tree-work-budget

Conversation

@calixteman

Copy link
Copy Markdown
Contributor

Some Type 4 functions take exponential time or overflow the stack when converted to a tree: chains of ifs that change the stack depth, comparisons of identical but separate DAGs (dup mul chains), and very deep nesting or expressions.

This PR adds an instruction/comparison work budget and limits fork depth, expression depth and procedure nesting. Functions that hit a limit fall back to PSStackBasedInterpreter, except nesting that is too deep, which the parser rejects.

@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Viewer preview

🗑️ Viewer previews removed.

sync-pdfs-for-pdf-js Bot pushed a commit to mozilla/pdf.js.refs that referenced this pull request Oct 18, 2026
@codecov-commenter

codecov-commenter commented Oct 18, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.91667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.46%. Comparing base (98cfa3e) to head (9815e4e).

Files with missing lines Patch % Lines
src/core/postscript/ast.js 97.91% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #22231      +/-   ##
==========================================
+ Coverage   90.44%   90.46%   +0.01%     
==========================================
  Files         277      277              
  Lines       68216    68243      +27     
==========================================
+ Hits        61699    61734      +35     
+ Misses       6517     6509       -8     
Flag Coverage Δ
browsertest 66.35% <85.41%> (-0.01%) ⬇️
fonttest 8.97% <ø> (ø)
integrationtest 69.41% <41.66%> (-0.01%) ⬇️
unittest 60.77% <97.91%> (+0.02%) ⬆️
unittestcli 58.52% <97.91%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codspeed

codspeed Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 86 untouched benchmarks


Comparing calixteman:ps-tree-work-budget (9815e4e) with master (98cfa3e)

Open in CodSpeed

@timvandermeij timvandermeij left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me, with the comment addressed. Thanks!

Comment thread src/core/postscript/ast.js Resolved
sync-pdfs-for-pdf-js Bot pushed a commit to mozilla/pdf.js.refs that referenced this pull request Oct 18, 2026
Stack-growing `if` forks and comparisons of distinct DAGs can take
exponential work. Limit instruction and comparison work and fork depth;
the JS builder uses the interpreter when conversion exceeds a limit.
Cap expression depth to bound recursive comparison, sharing analysis and
code generation. The JS builder interprets deeper expressions. Reject
excessive procedure nesting during parsing.
sync-pdfs-for-pdf-js Bot pushed a commit to mozilla/pdf.js.refs that referenced this pull request Oct 18, 2026
@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Reference tests

Results for 9815e4e (run, references from mozilla/pdf.js.refs@fce2c7a732).

Platform Status Tests Total runtime Errors Different FBF No reference Report
Linux ⚠️ 1399 13m 4s 0 1 0 0 view differences
Windows ✅ 1399 16m 8s 0 0 0 0

The report is kept for 30 days and replaced by the next run.

sync-pdfs-for-pdf-js Bot pushed a commit to mozilla/pdf.js.refs that referenced this pull request Oct 18, 2026
@calixteman
calixteman merged commit 28e406a into mozilla:master Oct 18, 2026
28 checks passed
@calixteman
calixteman deleted the ps-tree-work-budget branch October 18, 2026 20:02
sync-pdfs-for-pdf-js Bot pushed a commit to mozilla/pdf.js.refs that referenced this pull request Oct 18, 2026

This branch was previously deployed

1 inactive deployment
sync_pdfs — 9815e4ea Deployed Oct 18, 2026 by calixteman via request #498
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants