Skip to content

Commit 3f96d00

Browse files
authored
fix(pdu): set COMPRESSION_USED on the FastPath update header when compressed (#1382)
1 parent 0a461b5 commit 3f96d00

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

crates/ironrdp-pdu/src/basic_output/fast_path/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,15 @@ impl Encode for FastPathUpdatePdu<'_> {
141141
let mut header = 0u8;
142142
header.set_bits(0..4, self.update_code.as_u8());
143143
header.set_bits(4..6, self.fragmentation.as_u8());
144+
if self.compression_flags.is_some() {
145+
// The COMPRESSION_USED bit must be set on the header byte before it
146+
// is written, so the decoder knows a compression flags byte follows.
147+
header.set_bits(6..8, Compression::COMPRESSION_USED.bits());
148+
}
144149

145150
dst.write_u8(header);
146151

147152
if self.compression_flags.is_some() {
148-
header.set_bits(6..8, Compression::COMPRESSION_USED.bits());
149153
let compression_flags_with_type =
150154
self.compression_flags.map(|f| f.bits()).unwrap_or(0) | self.compression_type.map_or(0, |f| f.as_u8());
151155
dst.write_u8(compression_flags_with_type);

crates/ironrdp-pdu/src/basic_output/fast_path/tests.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,23 @@ fn palette_decode_with_code_returns_palette_variant() {
196196
other => panic!("Expected Palette variant, got: {other:?}"),
197197
}
198198
}
199+
200+
#[test]
201+
fn compressed_update_round_trips() {
202+
// The encoder must set the COMPRESSION_USED bit on the update header when
203+
// compression flags are present, otherwise the decoder does not consume the
204+
// trailing compression flags byte and misreads the data length.
205+
let data = [0xAAu8; 8];
206+
let pdu = FastPathUpdatePdu {
207+
fragmentation: Fragmentation::Single,
208+
update_code: UpdateCode::SurfaceCommands,
209+
compression_flags: Some(CompressionFlags::COMPRESSED),
210+
compression_type: Some(CompressionType::K64),
211+
data: &data,
212+
};
213+
214+
let mut buffer = vec![0u8; pdu.size()];
215+
encode(&pdu, buffer.as_mut_slice()).unwrap();
216+
217+
assert_eq!(pdu, decode::<FastPathUpdatePdu<'_>>(&buffer).unwrap());
218+
}

0 commit comments

Comments
 (0)