Skip to content

Prevent NaN values in sampled functions with a degenerate Domain - #21891

Merged
calixteman merged 1 commit into
mozilla:masterfrom
NakuRei:fix-sampled-function-zero-width-domain
Sep 7, 2026
Merged

Prevent NaN values in sampled functions with a degenerate Domain#21891
calixteman merged 1 commit into
mozilla:masterfrom
NakuRei:fix-sampled-function-zero-width-domain

Conversation

@NakuRei

@NakuRei NakuRei commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Overview

Type 0 (sampled) function evaluation divides by zero when a Domain entry has identical bounds, causing every output to become NaN and the affected content to render as black. This occurs in real-world documents that use a DeviceN color space containing a /None colorant, where the tint transform specifies [0 0] as the Domain for that input. No warning or error is logged, so the issue is not visible in the console.

The fix mirrors the existing guard used for stitching functions and matches PDFium's behavior.

Reproduction

The reduced test file test/pdfs/devicen-none-zero-domain.pdf (added in this PR) paints two rectangles using such a color space: the left one with a 50% tint of the spot color, and the right one with 100% black. Without this patch, both rectangles are rendered as solid black in the current pdfjs-dist release (6.3.289) as well as on master.

The behavior is browser-independent, since the issue arises entirely from function evaluation.

Before:
repro-before

After:
repro-after

The original document that exposed this issue is a commercial ebook and therefore cannot be shared. The reduced file reproduces the same color-space and function structure.

Comment thread src/core/function.js Outdated
Some documents use a DeviceN colour space that includes a `/None`
colorant, and their tint transform declares a zero-width Domain such
as `[0 0]` for that input because it never contributes to the output.
The interpolation then divides by zero, every output of the function
becomes NaN, and all content painted with that colour space ends up
black.

Handle it the same way the stitching function already guards against
a zero-width interval, which also matches what PDFium does.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@NakuRei
NakuRei force-pushed the fix-sampled-function-zero-width-domain branch from 4d8ff29 to bd4e415 Compare September 6, 2026 15:26
@codecov-commenter

codecov-commenter commented Sep 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.19%. Comparing base (716aff9) to head (bd4e415).
⚠️ Report is 23 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #21891      +/-   ##
==========================================
- Coverage   90.28%   90.19%   -0.09%     
==========================================
  Files         264      264              
  Lines       67273    67340      +67     
==========================================
  Hits        60737    60737              
- Misses       6536     6603      +67     
Flag Coverage Δ
fonttest 8.92% <ø> (ø)
integrationtest 69.43% <100.00%> (+<0.01%) ⬆️
unittest 58.58% <100.00%> (+0.10%) ⬆️
unittestcli 57.15% <100.00%> (+0.14%) ⬆️

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.

@calixteman calixteman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Thank you.

@calixteman
calixteman merged commit 3463d92 into mozilla:master Sep 7, 2026
20 of 22 checks passed
@calixteman

Copy link
Copy Markdown
Contributor

/botio makeref

@moz-tools-bot

Copy link
Copy Markdown
Collaborator

From: Bot.io (Linux m4)


Received

Command cmd_makeref from @calixteman received. Current queue size: 0

Live output at: http://54.241.84.105:8877/c66a3fe9f95187d/output.txt

@moz-tools-bot

Copy link
Copy Markdown
Collaborator

From: Bot.io (Windows)


Received

Command cmd_makeref from @calixteman received. Current queue size: 0

Live output at: http://54.193.163.58:8877/3713f6649d94bcb/output.txt

@moz-tools-bot

Copy link
Copy Markdown
Collaborator

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/c66a3fe9f95187d/output.txt

Total script time: 18.99 mins

  • Make references: Passed
  • Check references: Passed

@moz-tools-bot

Copy link
Copy Markdown
Collaborator

From: Bot.io (Windows)


Success

Full output at http://54.193.163.58:8877/3713f6649d94bcb/output.txt

Total script time: 23.66 mins

  • Make references: Passed
  • Check references: Passed

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.

5 participants