// 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 serialised 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 serialised 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 serialised data could cause an OOM crash .
fn deserialize_bytes() {
        let wrapper = Wrapper([255]);
        let serialised_wrapper = unwrap!(serialise(&wrapper));
        // 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!(serialised_wrapper, [1, 0, 0, 0, 0, 0, 0, 0, 255]);
        let deserialised_wrapper: Wrapper = unwrap!(deserialise(&serialised_wrapper));
        assert_eq!(wrapper, deserialised_wrapper);
        // Try to trigger an OOM crash.
        let tampered = [255u8; 9];
        match unwrap_err!(deserialise::<Wrapper>(&tampered)) {
            SerialisationError::Deserialise(_) => (),
            err => panic!("{:?}", err),
        }
        match unwrap_err!(deserialise::<Wrapper>(&[1, 0, 0, 0, 0, 0, 0, 0, 255, 255])) {
            SerialisationError::DeserialiseExtraBytes => (),
            err => panic!("{:?}", err),
        }
    }
fn deserialize_bytes ( ) { let wrapper = Wrapper ( [ 255 ] ) ; let serialised_wrapper = unwrap ! ( serialise ( wrapper ) ) ; // 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 ! ( serialised_wrapper [ 1 0 0 0 0 0 0 0 255 ] ) ; let deserialised_wrapper : Wrapper = unwrap ! ( deserialise ( serialised_wrapper ) ) ; assert_eq ! ( wrapper deserialised_wrapper ) ; // Try to trigger an OOM crash. let tampered = [ 255u8 ; 9 ] ; match unwrap_err ! ( deserialise Wrapper ( tampered ) ) { SerialisationError :: Deserialise ( _ ) => ( ) , err => panic ! ( " " err ) , } match unwrap_err ! ( deserialise Wrapper ( [ 1 0 0 0 0 0 0 0 255 255 ] ) ) { SerialisationError :: DeserialiseExtraBytes => ( ) , err => panic ! ( " " err ) , } }
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 .