Prevent NaN values in sampled functions with a degenerate Domain - #21891
Conversation
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>
4d8ff29 to
bd4e415
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
/botio makeref |
From: Bot.io (Linux m4)ReceivedCommand cmd_makeref from @calixteman received. Current queue size: 0 Live output at: http://54.241.84.105:8877/c66a3fe9f95187d/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_makeref from @calixteman received. Current queue size: 0 Live output at: http://54.193.163.58:8877/3713f6649d94bcb/output.txt |
From: Bot.io (Linux m4)SuccessFull output at http://54.241.84.105:8877/c66a3fe9f95187d/output.txt Total script time: 18.99 mins
|
From: Bot.io (Windows)SuccessFull output at http://54.193.163.58:8877/3713f6649d94bcb/output.txt Total script time: 23.66 mins
|
Overview
Type 0 (sampled) function evaluation divides by zero when a
Domainentry 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/Nonecolorant, where the tint transform specifies[0 0]as theDomainfor 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 currentpdfjs-distrelease (6.3.289) as well as onmaster.The behavior is browser-independent, since the issue arises entirely from function evaluation.
Before:

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.