File tree Expand file tree Collapse file tree
crates/ironrdp-pdu/src/basic_output/fast_path Expand file tree Collapse file tree Original file line number Diff line number Diff 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) ;
Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments