Repository navigation
fix(hide): read the preview's pixels at 8 bits a channel - #987
Merged
Merged
Conversation
The Pixelate / blur window turned its preview into a bitmap from ImageMagick's "BGRA" output, which keeps the picture's own depth: a 1-bit grey or palette PNG (a flat screenshot, a diagram) gave an eighth of the bytes, and the bitmap, reading four bytes a pixel, ran past their end and could crash Filee. The pixels are now read from the picture's pixel data, 8 bits a channel whatever depth it was stored with, and their count is checked before the bitmap is made. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
KnifeLemon
approved these changes
Nov 2, 2026
KnifeLemon
left a comment
Owner
There was a problem hiding this comment.
Thanks, @lightscape-jm. A clear catch, with numbers that show it:
ToByteArray(MagickFormat.Bgra)keeps the stored depth, so a 1-bit PNG gave an eighth of the bytes, and the bitmap read past the end of the buffer;GetPixels().ToByteArray(PixelMapping.BGRA)is 8 bits a channel whatever the depth;- the length check turns any future mismatch into an error instead of a bad read.
Checking PdfCompressor.EncodeFlate for the same pattern was a good extra. CI is green. Merging.
7 of 12 tasks
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.
What does this change?
The small preview fix from #877 (#3 in the plan), on its own before Annotate.
The Pixelate / blur window turns its preview into a bitmap from ImageMagick's
MagickFormat.Bgraoutput, which keeps the picture's own depth. A PNG stored at 1 bit a channel (a flat screenshot, a diagram, a two-colour palette) gives an eighth of the bytes. The bitmap reads four bytes a pixel from the pinned buffer, so it reads past the end, which can show wrong pixels or crash.Measured on current
mainthroughHideService.LoadPreviewAsync, for a plain white 40 × 30 PNG and a two-colour palette PNG (both saved by ImageMagick at depth 1):ToByteArray(MagickFormat.Bgra)The pixels are now read from the pixel collection (
GetPixels().ToByteArray(PixelMapping.BGRA)), which is 8 bits a channel whatever depth the picture was stored with, and their count is checked before the bitmap is made, so a mismatch is an error instead of a read past the end.I looked for the same pattern elsewhere:
PdfCompressor.EncodeFlatealso writes raw pixels, but it setsDepth = 8first and checks the length, so it's fine.Type of change
How was it tested?
dotnet format --verify-no-changesdotnet test: the App Pixelate / blur tests (33, including the new one) pass.main; with this change the same pictures give 4,800 bytes in their real colours.New test (
tests/Filee.App.Tests/HidePreviewPixelsTests.cs):A_one_bit_and_a_palette_png_give_four_bytes_a_pixel_in_their_coloursScreenshots (UI changes)
None.
Checklist
src/Filee.App/Assets/i18n/*.jsonfiles (none)THIRD-PARTY-NOTICES.md(none)🤖 Generated with Claude Code