fn deserialize_bytes() {
        let wrapper = Wrapper([255]);
        let serialized_wrapper = serialize(&wrapper).unwrap();
        // If the following assertion fails, revisit how we're encoding data via `serialize_bytes`
        // to check that the following `tampered` array below is still trying to trigger an OOM
        // error.
        assert_eq!(serialized_wrapper, [1, 0, 0, 0, 0, 0, 0, 0, 255]);
        let deserialized_wrapper: Wrapper = deserialize(&serialized_wrapper).unwrap();
        assert_eq!(wrapper, deserialized_wrapper);

        // Try to trigger an OOM crash.
        let tampered = [255u8; 9];
        match deserialize::<Wrapper>(&tampered).unwrap_err() {
            DeserializationError::GenericBincode(_) => (),
            err => panic!("{:?}", err),
        }

        assert_eq!(
            deserialize::<Wrapper>(&[1, 0, 0, 0, 0, 0, 0, 0, 255, 255]),
            Err(DeserializationError::BytesLeftOver)
        );
    }
// The bincode implementation of `serialize_bytes` puts the number of bytes of raw data as the
// first 8 bytes of the encoded data.  The corresponding `deserialize_bytes` uses these first 8
// bytes to deduce the size of the buffer into which the raw bytes should then be copied.  If we
// use bincode's `deserialize_from(.., Infinite)` to try and parse such data, size-checking is
// disabled when allocating the buffer, and corrupted serialized data could cause an OOM crash.
The bincode implementation of `serialize_bytes` puts the number of bytes of raw data as the
first 8 bytes of the encoded data.  The corresponding `deserialize_bytes` uses these first 8
bytes to deduce the size of the buffer into which the raw bytes should then be copied.  If we
use bincode's `deserialize_from(.., Infinite)` to try and parse such data, size-checking is
disabled when allocating the buffer, and corrupted serialized data could cause an OOM crash.
The bincode implementation of ` serialize_bytes ` puts the number of bytes of raw data as the first 8 bytes of the encoded data . The corresponding ` deserialize_bytes ` uses these first 8 bytes to deduce the size of the buffer into which the raw bytes should then be copied . If we use bincode ' s ` deserialize_from ( .. Infinite ) ` to try and parse such data size - checking is disabled when allocating the buffer and corrupted serialized data could cause an OOM crash .
fn deserialize_bytes() {
        let wrapper = Wrapper([255]);
        let serialized_wrapper = serialize(&wrapper).unwrap();
        // If the following assertion fails, revisit how we're encoding data via `serialize_bytes`
        // to check that the following `tampered` array below is still trying to trigger an OOM
        // error.
        assert_eq!(serialized_wrapper, [1, 0, 0, 0, 0, 0, 0, 0, 255]);
        let deserialized_wrapper: Wrapper = deserialize(&serialized_wrapper).unwrap();
        assert_eq!(wrapper, deserialized_wrapper);
        // Try to trigger an OOM crash.
        let tampered = [255u8; 9];
        match deserialize::<Wrapper>(&tampered).unwrap_err() {
            DeserializationError::GenericBincode(_) => (),
            err => panic!("{:?}", err),
        }
        assert_eq!(
            deserialize::<Wrapper>(&[1, 0, 0, 0, 0, 0, 0, 0, 255, 255]),
            Err(DeserializationError::BytesLeftOver)
        );
    }
fn deserialize_bytes ( ) { let wrapper = Wrapper ( [ 255 ] ) ; let serialized_wrapper = serialize ( & wrapper ) . unwrap ( ) ; // If the following assertion fails, revisit how we're encoding data via `serialize_bytes` // to check that the following `tampered` array below is still trying to trigger an OOM // error. assert_eq ! ( serialized_wrapper [ 1 0 0 0 0 0 0 0 255 ] ) ; let deserialized_wrapper : Wrapper = deserialize ( & serialized_wrapper ) . unwrap ( ) ; assert_eq ! ( wrapper deserialized_wrapper ) ; // Try to trigger an OOM crash. let tampered = [ 255u8 ; 9 ] ; match deserialize :: < Wrapper > ( & tampered ) . unwrap_err ( ) { DeserializationError :: GenericBincode ( _ ) => ( ) , err => panic ! ( " " err ) , } assert_eq ! ( deserialize Wrapper ( [ 1 0 0 0 0 0 0 0 255 255 ] ) Err ( DeserializationError BytesLeftOver ) ) ; }
The bincode implementation of `serialize_bytes` puts the number of bytes of raw data as the
first 8 bytes of the encoded data.
The bincode implementation of ` serialize_bytes ` puts the number of bytes of raw data as the first 8 bytes of the encoded data .