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: TiffImageLoader null options, a second ColorMap escape, and a 1GB allocation from 138 bytes #534
Three findings on TiffImageLoader from the #504 documentation review, all measured, none introduced by that branch.
A null options is an input-dependent null dereference.Load(byte[], ImageLoadOptions) is public and reads options.BitDepth only inside its 16-bit branches, so whether a null argument survives depends on the file:
CcittImageLoader.Load explicitly documents that its options accepts null and takes the default, so a caller carrying that expectation across gets a crash that depends on the image rather than on the call. Either guard it or document it; guarding it matches the sibling.
A second input escapes both documented exception types, at a different site from #512. A palette TIFF whose ColorMap tag carries count 0 and a wholly positive in-file offset reaches BuildPalette and throws IndexOutOfRangeException from colorMap[0], with no negative value anywhere in the file. Bisected: count 0 throws; counts 1, 2, 3 and 6 load. paletteSize = colorMap.Length / 3 is 0 for counts 0 through 2, but only length 0 makes the indexer out of range. #512 covers the negative-offset route in ReadColorMap; this is a separate one and needs its own guard.
An arbitrary allocation precedes the #512 throw. A 138-byte TIFF declaring a ColorMap count of 500,000,000 allocated 1,000,001,280 bytes on the calling thread before raising. Measured at count 6 → 14,928 bytes and count 60,000,000 → 120,001,024 bytes, so it scales with the declared count. ReadColorMap allocates new ushort[count] from an unvalidated tag count and lacks the plausibility guard ReadTagArray carries. The pixel cap does not help: it is checked against the image dimensions, not against a tag count. Higher counts were not tested, so the supported claim is one gigabyte from 138 bytes rather than an unbounded one.
All three are in the same method family and are worth one pass. Commit a fixture per case.
A fourth item for this issue, found by the round-four contract review of #504.
ExtraSamples is read and discarded.TiffImageLoader assigns the tag at the switch and never reads it again; hasAlpha is derived solely from samplesPerPixel == 4 && photometric == 2. Measured, the tag makes no difference to the output at all:
ExtraSamples absent : RGB=C86432… SMask present identical to baseline
ExtraSamples = 0 : RGB=C86432… SMask present identical to baseline
ExtraSamples = 1 : RGB=C86432… SMask present identical to baseline
ExtraSamples = 2 : RGB=C86432… SMask present identical to baseline
TIFF 6.0 p. 31 defines 1 as associated alpha, with the colour pre-multiplied, and 2 as unassociated alpha. ISO 32000-2 §11.6.5.2 requires that pre-blended image data carry a Matte entry in the soft-mask image dictionary. So a conforming pre-multiplied TIFF is emitted as a plain /SMask with no /Matte and composites wrong, and ExtraSamples = 0, which means unspecified data rather than alpha, is treated as alpha anyway.
This is the same class as the rest of this issue: a tag the loader neither honours nor refuses, producing a different image with nothing reported.
Activity
docs(kernel): say what TIFF ignores, and stop claiming an accepted set
Tim81 commentedon Sep 14, 2026
A fourth item for this issue, found by the round-four contract review of #504.
ExtraSamplesis read and discarded.TiffImageLoaderassigns the tag at the switch and never reads it again;hasAlphais derived solely fromsamplesPerPixel == 4 && photometric == 2. Measured, the tag makes no difference to the output at all:TIFF 6.0 p. 31 defines 1 as associated alpha, with the colour pre-multiplied, and 2 as unassociated alpha. ISO 32000-2 §11.6.5.2 requires that pre-blended image data carry a
Matteentry in the soft-mask image dictionary. So a conforming pre-multiplied TIFF is emitted as a plain/SMaskwith no/Matteand composites wrong, andExtraSamples = 0, which means unspecified data rather than alpha, is treated as alpha anyway.This is the same class as the rest of this issue: a tag the loader neither honours nor refuses, producing a different image with nothing reported.
docs(kernel): say what TIFF ignores, and stop claiming an accepted set
docs(kernel): say what the image loaders refuse, and how JPEG differs (…
fix(kernel): BMP and TIFF loaders check pixel data before allocating (#…