Skip to content

fix(cliprdr): accept CF_DIB with BITFIELDS compression and standard masks - #1940

Draft
Marynych Oleksandr (maryny4) wants to merge 1 commit into
Devolutions:masterfrom
maryny4:fix/cliprdr-dib-v1-bitfields
Draft

fix(cliprdr): accept CF_DIB with BITFIELDS compression and standard masks#1940
Marynych Oleksandr (maryny4) wants to merge 1 commit into
Devolutions:masterfrom
maryny4:fix/cliprdr-dib-v1-bitfields

Conversation

@maryny4

Copy link
Copy Markdown
Contributor

Windows commonly puts 32bpp CF_DIB on the clipboard with BI_BITFIELDS compression and the standard BGRA color masks. The CF_DIBV5 path already accepts that and validates the masks, but the CF_DIB path rejected every compression other than BI_RGB, so dib_to_png failed and consumers such as ironrdp-web and ironrdp-daemon dropped the image; a downstream project has to rewrite the header to BI_RGB to paste it at all.

With the standard masks the pixels are laid out exactly as with BI_RGB, so once the masks are validated they decode the same way. This moves the mask validation shared with BITMAPV5HEADER into one helper, reads the three masks that follow a BITFIELDS BITMAPINFOHEADER (the V1 layout carries no alpha mask) and accounts for them in the logical length reported by validate_dib. Non-standard mask orders stay rejected on both paths, as before.

Tests build the BITFIELDS variants from the existing cf_dib.pdu and cf_dibv5.pdu fixtures. A V1 BITFIELDS DIB with standard masks decodes to a PNG byte-identical to the BI_RGB fixture and validate_dib reports the full length including the masks; a non-standard mask order is refused; masks cut off mid-header are a decode error rather than a panic; and the V5 path keeps its previous behavior through the shared helper.

…asks

Windows commonly places 32bpp `CF_DIB` on the clipboard with `BI_BITFIELDS`
compression and the standard BGRA color masks. The `CF_DIBV5` path already
accepts that and validates the masks, but the `CF_DIB` path rejected every
compression other than `BI_RGB`, so `dib_to_png` failed and consumers such
as `ironrdp-web` and `ironrdp-daemon` dropped the image; a downstream
project has to rewrite the header to `BI_RGB` to paste it at all.

With the standard masks the pixels are laid out exactly as with `BI_RGB`, so
once the masks are validated they decode the same way. Move the mask
validation shared with `BITMAPV5HEADER` into one helper, read the three
masks that follow a `BITFIELDS` `BITMAPINFOHEADER` (the V1 layout has no
alpha mask) and account for them in the logical length reported by
`validate_dib`. Non-standard mask orders stay rejected on both paths.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant