@@ -242,39 +242,29 @@ impl<'de> Decode<'de> for Codec {
242
242
let id = src. read_u8 ( ) ;
243
243
let codec_properties_len = usize:: from ( src. read_u16 ( ) ) ;
244
244
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 ! ( ) ,
274
264
}
275
- GUID_IGNORE => CodecProperty :: Ignore ,
276
- _ => CodecProperty :: None ,
277
265
}
266
+ GUID_IGNORE => CodecProperty :: Ignore ,
267
+ _ => CodecProperty :: None ,
278
268
} ;
279
269
280
270
Ok ( Self { id, property } )
@@ -394,6 +384,8 @@ impl Encode for RfxClientCapsContainer {
394
384
395
385
impl < ' de > Decode < ' de > for RfxClientCapsContainer {
396
386
fn decode ( src : & mut ReadCursor < ' de > ) -> DecodeResult < Self > {
387
+ ensure_fixed_part_size ! ( in: src) ;
388
+
397
389
let _length = src. read_u32 ( ) ;
398
390
let capture_flags = CaptureFlags :: from_bits_truncate ( src. read_u32 ( ) ) ;
399
391
let _caps_length = src. read_u32 ( ) ;
0 commit comments