Repository navigation
D3D11 graphics: fail a PNG whose pixel stream does not decode - #1263
Draft
iamfatness wants to merge 1 commit into
Draft
iamfatness wants to merge 1 commit into
iamfatness wants to merge 1 commit into
Conversation
WIC's PNG decoder never reports a corrupt IDAT. For a bad zlib header, a malformed deflate block, a truncated stream, or a wrong Adler-32, CopyPixels and CreateBitmapFromWicBitmap return S_OK with zeroed pixels. A short stream returns a partial picture. This was measured on build 26300. As a result, the D3D11 raster prepared such an asset as ready with an empty warning and aired a blank. The Mac raster fails it. openPackagedImage now inflates the IDAT data once on the preparation worker. The stream must inflate completely, match its Adler-32, and carry every byte that IHDR implies. If it does not, decodeOverlayImage refuses the image, and both call sites report the existing wording, "Graphics image could not be decoded: <id>". JPEG and file-URI images are unchanged. This fixes OverlayRasterContract.FailedScaleKeepsTheAcceptedRaster, OverlayRasterContract.ImageDecodeFailureWording and GraphicsTemplateRegistry.ABrokenTemplateThumbnailDoesNotBlockTheOthers on D3D11. It also corrects two comments that claimed WIC surfaces the failure, and adds a gotcha entry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On Windows, a graphics image asset can be a PNG with a valid header and a zeroed IDAT payload. The D3D11 raster prepared that asset as
readywith an empty warning, so it aired a blank. The Mac raster fails it withGraphics image could not be decoded: <id>. Because of this, three tests were red onmain:OverlayRasterContract.FailedScaleKeepsTheAcceptedRasterOverlayRasterContract.ImageDecodeFailureWordingGraphicsTemplateRegistry.ABrokenTemplateThumbnailDoesNotBlockTheOthersRoot cause (measured, build 26300)
The brief guessed that WIC decodes lazily, but that is not the cause. WIC never reports the failure anywhere. For the zeroed payload, the frame's
CopyPixels, the format converter'sCopyPixels,CreateBitmapFromWicBitmapon the software WIC render target, andEndDrawall returnS_OK. The pixels come back as zeros. A standalone probe also tried a bad zlib header, a valid header with a zeroed body, a bad Adler-32, a bad stored LEN/NLEN, a truncated stream and a reserved block type. WIC returnedS_OKand all-zero pixels for every one. A stream that is valid but short returns a partial picture. So no HRESULT check indecodeOverlayImage(CompositorOverlayRaster.cpp) can catch it. Two comments, in the Mac raster and in the contract fixture, claimed that WIC'sCreateBitmapFromWicBitmapsurfaces this failure. That is wrong.Fix
openPackagedImagenow runspngPixelStreamDecodesonce on the preparation worker and records the result inImageInput::pixelsDecode. This is a strict zlib/deflate verifier over the IDAT chunks. The stream must inflate completely, match its Adler-32, and produce at least the byte count that IHDR implies. The count includes Adam7 and every colour type and bit depth. Work is capped at twice the expected bytes.decodeOverlayImagenow takes theImageInputand refuses one whose pixels do not decode. Both existing call sites therefore report the existing failure wording (the template path:Graphics image could not be decoded: <id>).The verifier matches WIC's behaviour exactly on all 10 probe variants: every case where WIC zero-fills or returns a partial picture is rejected. A bad filter byte and trailing extra data are accepted, as WIC accepts them. It also accepts all 280 real PNGs tried: 74 from this repo (macOS and Windows screenshots, goldens, app assets) and 206 generated ones. The generated set covers colour types 0/2/3/4/6, depths 1 to 16, interlaced and non-interlaced images, zlib levels 0/1/6/9, and IDAT split across chunks. Cost: about 26 ms for a 1440p screenshot, 76 ms for a 4096x4096 gradient, and 298 ms for 67 MB of incompressible 16 MP data, which is above the 32 MB asset limit anyway. This runs on the worker, not the render thread.
Tests (Release,
native/build-dev, Windows build 26300)OverlayRasterContract.*:GraphicsRasterParity*:GraphicsCompositionPixel.*:GraphicsTemplateRegistry.*Graphics*:D3D11*:OverlayRaster*:OverlayTile*:ParityPng.*The one failure that remains is
OverlayRasterContract.CrawlAtTheItemLimitPreparesOrFailsWithAtlasWording. Before and after, it fails with the same message: "Graphics preparation exceeded its admitted budget." It is the long-crawl admission defect, and its fix is in draft PR #1258, which this PR does not include. No test, tolerance or fixture logic changed. Only one fixture comment was edited.Not verified
.mmedit.🤖 Generated with Claude Code