@@ -241,39 +241,29 @@ impl<'de> Decode<'de> for Codec {
241241 let id = src. read_u8 ( ) ;
242242 let codec_properties_len = usize:: from ( src. read_u16 ( ) ) ;
243243
244- let property = if codec_properties_len != 0 {
245- ensure_size ! ( in: src, size: codec_properties_len) ;
246- let property_buffer = src. read_slice ( codec_properties_len) ;
247-
248- match guid {
249- GUID_NSCODEC => CodecProperty :: NsCodec ( decode ( property_buffer) ?) ,
250- GUID_REMOTEFX | GUID_IMAGE_REMOTEFX => {
251- let property = if property_buffer[ 0 ] == 0 {
252- RemoteFxContainer :: ServerContainer ( codec_properties_len)
253- } else {
254- RemoteFxContainer :: ClientContainer ( decode ( property_buffer) ?)
255- } ;
256-
257- match guid {
258- GUID_REMOTEFX => CodecProperty :: RemoteFx ( property) ,
259- GUID_IMAGE_REMOTEFX => CodecProperty :: ImageRemoteFx ( property) ,
260- _ => unreachable ! ( ) ,
261- }
262- }
263- GUID_IGNORE => CodecProperty :: Ignore ,
264- _ => CodecProperty :: None ,
265- }
266- } else {
267- match guid {
268- GUID_NSCODEC | GUID_REMOTEFX | GUID_IMAGE_REMOTEFX => {
269- return Err ( invalid_field_err ! (
270- "codecPropertiesLen" ,
271- "invalid codec property length"
272- ) ) ;
244+ ensure_size ! ( in: src, size: codec_properties_len) ;
245+ let property_buffer = src. read_slice ( codec_properties_len) ;
246+
247+ let property = match guid {
248+ GUID_NSCODEC => CodecProperty :: NsCodec ( decode ( property_buffer) ?) ,
249+ GUID_REMOTEFX | GUID_IMAGE_REMOTEFX => {
250+ let byte = property_buffer
251+ . first ( )
252+ . ok_or_else ( || invalid_field_err ! ( "remotefx property" , "must not be empty" ) ) ?;
253+ let property = if * byte == 0 {
254+ RemoteFxContainer :: ServerContainer ( codec_properties_len)
255+ } else {
256+ RemoteFxContainer :: ClientContainer ( decode ( property_buffer) ?)
257+ } ;
258+
259+ match guid {
260+ GUID_REMOTEFX => CodecProperty :: RemoteFx ( property) ,
261+ GUID_IMAGE_REMOTEFX => CodecProperty :: ImageRemoteFx ( property) ,
262+ _ => unreachable ! ( ) ,
273263 }
274- GUID_IGNORE => CodecProperty :: Ignore ,
275- _ => CodecProperty :: None ,
276264 }
265+ GUID_IGNORE => CodecProperty :: Ignore ,
266+ _ => CodecProperty :: None ,
277267 } ;
278268
279269 Ok ( Self { id, property } )
@@ -393,6 +383,8 @@ impl Encode for RfxClientCapsContainer {
393383
394384impl < ' de > Decode < ' de > for RfxClientCapsContainer {
395385 fn decode ( src : & mut ReadCursor < ' de > ) -> DecodeResult < Self > {
386+ ensure_fixed_part_size ! ( in: src) ;
387+
396388 let _length = src. read_u32 ( ) ;
397389 let capture_flags = CaptureFlags :: from_bits_truncate ( src. read_u32 ( ) ) ;
398390 let _caps_length = src. read_u32 ( ) ;
0 commit comments