rustdesk/rustdesk · error
Invalid mask cursor buffer size, got {} bytes, expected {}
Error message
Invalid mask cursor buffer size, got {} bytes, expected {} What it means
Post-copy sanity check: the number of mask bytes actually retrieved does not match the expected bmWidthBytes × bmHeight buffer size. This indicates the OS delivered a different mask layout than the BITMAP header advertised (stale handle or unusual driver), so the buffer is unusable for building valid cursor data.
Source
Thrown at src/platform/windows.rs:285
let mut height = if ii.is_color() {
bm_mask.bmHeight
} else {
bm_mask.bmHeight / 2
};
let cbits_size = width * height * 4;
if cbits_size < 16 {
bail!("Invalid icon: too small"); // solve some crash
}
let mut cbits: Vec<u8> = Vec::new();
cbits.resize(cbits_size as _, 0);
let mut mbits: Vec<u8> = Vec::new();
mbits.resize((bm_mask.bmWidthBytes * bm_mask.bmHeight) as _, 0);
let r = GetBitmapBits(ii.0.hbmMask, mbits.len() as _, mbits.as_mut_ptr() as _);
if r == 0 {
bail!("Failed to copy bitmap data");
}
if r != (mbits.len() as i32) {
bail!(
"Invalid mask cursor buffer size, got {} bytes, expected {}",
r,
mbits.len()
);
}
let do_outline;
if ii.is_color() {
get_rich_cursor_data(ii.0.hbmColor, width, height, &mut cbits)?;
do_outline = fix_cursor_mask(
&mut mbits,
&mut cbits,
width as _,
height as _,
bm_mask.bmWidthBytes as _,
);
} else {
do_outline = handleMask(
cbits.as_mut_ptr(),View on GitHub (pinned to 91c9fccbb0)
Solutions
- Discard this cursor frame and retry capture, since the mismatch usually stems from a cursor being replaced concurrently
- Validate the BITMAP header dimensions immediately before the copy and re-query GetObjectA if the cursor handle may be stale
- Skip serializing this cursor and keep the previously captured shape
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/platform/windows.rs:285 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of rustdesk/rustdesk@91c9fccbb0 (2026-09-10).
Data as JSON: /api/errors/5735c8894686a942.
Report an issue: GitHub.