Skip to content

fix(session): Fix bitmap stride mismatch and out-of-bounds writes for xRDP compatibility#1252

Open
Amartya Anshuman (amartyaa) wants to merge 1 commit intoDevolutions:masterfrom
amartyaa:master
Open

fix(session): Fix bitmap stride mismatch and out-of-bounds writes for xRDP compatibility#1252
Amartya Anshuman (amartyaa) wants to merge 1 commit intoDevolutions:masterfrom
amartyaa:master

Conversation

@amartyaa
Copy link
Copy Markdown

Fixes #1251

Summary

This PR fixes two related issues in ironrdp-session that cause diagonal bitmap distortion and index-out-of-bounds panics when connecting to xRDP servers.

Changes

crates/ironrdp-session/src/fast_path.rs

xRDP sends bitmap updates where the data dimensions (update.width × update.height) differ from the destination rectangle (update.rectangle). Per MS-RDPBCGR §2.2.9.1.1.3.1.2.2, bitmapWidth/bitmapHeight define the pixel data layout while destLeft/destTop/destRight/destBottom define the screen placement.
The apply_* methods use the rectangle's width as the row stride. Passing update.rectangle when it's wider/narrower than the actual data causes diagonal shearing.
Fix: Construct a blit_rect whose dimensions match the actual bitmap data, positioned at the destination's top-left corner:

let blit_rect = InclusiveRectangle {
    left: update.rectangle.left,
    top: update.rectangle.top,
    right: update.rectangle.left + update.width.saturating_sub(1),
    bottom: update.rectangle.top + update.height.saturating_sub(1),
};

crates/ironrdp-session/src/image.rs

Added bounds checks to all apply_* bitmap methods that were missing them:

  • apply_rgb16_bitmap
  • apply_rgb15_bitmap
  • apply_bgr24_bitmap
  • apply_rgb8_with_palette
  • apply_rgb24_iter
  • apply_rgb32_bitmap (both same-format and cross-format paths)
  • data_for_rect (clamped to buffer length)

Each pixel write is now guarded with if dst_idx + bytes_per_pixel < self.data.len().
This is consistent with how other parts of the codebase handle edge-of-framebuffer updates — pixels beyond the buffer are silently clipped rather than panicking.

Also added a max_rows clamp in apply_rgb24_iter to prevent iterating beyond the framebuffer height.

Testing

  • Tested against xRDP 0.10.x (Ubuntu 22.04, Xorg session with XFCE)
  • Verified correct rendering at 8bpp, 15bpp, 16bpp, 24bpp, and 32bpp
  • No more diagonal distortion on the xRDP login screen or desktop
  • No more panics during session startup or bitmap updates near framebuffer edges
  • Verified no regression when connecting to Windows RDP servers (Windows 10/11)

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.

ironrdp-session: Bitmap rendering crashes and diagonal distortion when connecting to xRDP

1 participant