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