You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Kernel: a PNG colour key with bits above the bit depth is written as a /Mask outside the sample range #768
PNG (W3C PNG 3rd edition, tRNS chunk) stores a grey or RGB colour key as two bytes per sample whatever the bit depth. When the bit
depth is below 16, only the low bits count: encoders should set the other bits to 0, and decoders must mask them to 0 before
using the value. So a PNG whose tRNS has stray high bits is still a valid PNG, and its key is the masked value.
ISO 32000-1 8.9.6.4 (and 32000-2 8.9.6.4): each integer of a colour-key Mask array shall be in the range 0 to
2^BitsPerComponent - 1.
PngImageLoader (colorKeyMask, lines 444 to 478 at 8d1f6a2) uses the raw 16-bit word for 8-bit images and multiplies it for
1, 2 and 4-bit images, without masking first.
Measured at 8d1f6a2, each PNG saved through LayoutImage.FromBytes under PDF/A-2b:
PNG
tRNS bytes
Written
Masked key a decoder uses
2 x 1 grey, 8 bit, samples 10 80
01 10
/BitsPerComponent 8 /Mask [272 272]
16
2 x 1 grey, 4 bit, samples 5 A
00 15
/BitsPerComponent 8 /Mask [357 357]
5, written as 85
2 x 1 RGB, 8 bit, red and green
01 FF 00 00 00 00
/BitsPerComponent 8 /Mask [511 511 0 0 0 0]
(255, 0, 0)
veraPDF 1.30.4 reports no failure for any of the three (it has no rule for the colour-key range). poppler (pdftoppm, 72 dpi) paints
the first pixel of each, which the PNG makes transparent: grey 16, grey 85 and red, where a white background is expected.
Sweep: git grep -n "colorKeyMask\|\"Mask\"" 8d1f6a2 -- src finds the colour-key Mask written only from PngImageLoader
(through PdfImageXObject). The other loaders express transparency as a soft mask built from bytes, so their values cannot
leave the range. The Reader's ImageDecoder reads Mask and was not examined.
Proposal
Mask the tRNS word to the source bit depth (raw16 & ((1 << bitDepth) - 1)) before the existing rescale, as the PNG
specification requires of a decoder. No PNG whose tRNS high bits are zero changes its output.
Acceptance
The three inputs above write [16 16], [85 85] and [255 255 0 0 0 0], and the first pixel of each is not painted.
Iso32000_1_8_9_6_4_AColourKeyIsPairsOfIntegersInsideTheSampleRangeAndNamesAStoredSample gains the three kinds.
A PNG whose tRNS high bits are zero writes the same bytes as before.
The tests that pin and accept this issue were renamed during the audit's review rounds; the acceptance section above names earlier ones. Current names, all in ConformanceAuditG4Tests (tests/VellumPdf.Kernel.Tests/ConformanceAuditG4Tests.*.cs, PR #765). A pin passes today and is rewritten by the fix; an accept test is skipped now and loses its skip with the fix; a keep test passes before and after.
Keep: Iso32000_1_8_9_6_4_AColourKeyIsPairsOfIntegersInsideTheSampleRangeAndNamesAStoredSample; also Iso32000_1_8_9_6_4_PinsTodayReducingToEightBitsWidensASixteenBitKeyToAllSamplesWithTheSameHighByte, which a masking fix leaves as it is.
Activity
test: answer the review of the graphics audit (#763, #764, #768, #769)
Tim81 commentedon Nov 29, 2026
The tests that pin and accept this issue were renamed during the audit's review rounds; the acceptance section above names earlier ones. Current names, all in
ConformanceAuditG4Tests(tests/VellumPdf.Kernel.Tests/ConformanceAuditG4Tests.*.cs, PR #765). A pin passes today and is rewritten by the fix; an accept test is skipped now and loses its skip with the fix; a keep test passes before and after.Iso32000_1_8_9_6_4_PinsTodayAPngKeyWithBitsAboveTheDepthIsWrittenOutsideTheSampleRange(three cases: grey 8, grey 4, RGB 8)Iso32000_1_8_9_6_4_APngKeyWithBitsAboveTheDepthIsMaskedBeforeItIsWritten(three cases, exact values[16 16],[85 85],[255 255 0 0 0 0])Iso32000_1_8_9_6_4_AColourKeyIsPairsOfIntegersInsideTheSampleRangeAndNamesAStoredSample; alsoIso32000_1_8_9_6_4_PinsTodayReducingToEightBitsWidensASixteenBitKeyToAllSamplesWithTheSameHighByte, which a masking fix leaves as it is.test: pin graphics and image output to its ISO clauses (#765)
fix(images): write a JP2 device name only for a channel count it fits
docs(conformance): mark the image gaps #763, #764, #768 and #770 fixed