Skip to content

Commit

Permalink
Rework decoding of Boxes, Rcs, Arcs, arrays and enums (stack ov…
Browse files Browse the repository at this point in the history
…erflow fix) (#426)

* Rework decoding of `Box`es, `Rc`s, `Arc`s and arrays

* Update changelog

* Bump version to 3.5.0

* Fix typo

* Reduce the size of an array in tests to make miri not run forever

* Make the `TypeInfo` match exhaustive

* Update dependencies

* Update benchmarks to criterion 0.4

* Update `BitVec` benchmarks too

* Fix the benchmarks for real this time

* Use `Layout::new` instead of `Layout::from_size_align`

Co-authored-by: Squirrel <giles@parity.io>

* Move blanket decoding of wrapper types into a default impl

* Fix stack overflow when decoding big nested enums

* Bump version of `parity-scale-codec-derive` to 3.5.0

* Move the crate-level docs into README and include README as docs

* Add a note regarding deserializing big arrays to the README

* Update the CHANGELOG again

* Remove one of the intermediate casts

This cast was a no-op anyway, but it's slightly confusing
as the length of the array in the pointer's type was incorrect,
so let's just remove it.

* README cleanups

* Add `rust` markers and make indentation consistent in README snippets

* Make `max-encoded-len` feature not force-enable `parity-scale-codec-derive`

* Reexport derive macros not when `parity-scale-codec-derive` is enabled but when `derive` is

* Update CHANGELOG again

* Fix `parity-scale-codec-derive` tests compilation

* Update `serde`

* Update comment in `src/codec.rs`

Co-authored-by: Bastian Köcher <git@kchr.de>

* Update comment in `src/codec.rs`

Co-authored-by: Roman <r.proskuryakoff@gmail.com>

* Move the version bounds for `parity-scale-codec-derive`

* Remove `DecodeContext`

* Move the array byte size calculations to compile-time

* Add a TODO about `Box::assume_init`

* Move `DecodeFinished` into its own module

* Add a TODO about `MaybeUninit::slice_assume_init_mut`

* Update the changelog

* `std` -> `core` so that no_std compiles

---------

Co-authored-by: Squirrel <giles@parity.io>
Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: Roman <r.proskuryakoff@gmail.com>
  • Loading branch information
4 people authored Jun 15, 2023
1 parent 26ec559 commit 0688c04
Show file tree
Hide file tree
Showing 11 changed files with 738 additions and 535 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ All notable changes to this crate are documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this crate adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.6.0] - 2023-06-15

### Added

- Added `Decode::decode_into` to allow deserializing into unitialized memory.
- Added a `DecodeFinished` type to be used with `Decode::decode_into`.

### Fixed

- Trying to deserialize a big boxed array (e.g. `Box<[u8; 1024 * 1024 * 1024]>`) won't overflow the stack anymore.
- Trying to deserialize big nested enums with many variants won't overflow the stack anymore.
- Elements of partially read arrays will now be properly dropped if the whole array wasn't decoded.

### Changed

- The derive macros will now be reexported only when the `derive` feature is enabled,
as opposed to how it was previously where enabling `parity-scale-codec-derive` would suffice.
- The `max-encoded-len` feature won't automatically enable the derive macros nor pull in the
`parity-scale-codec-derive` dependency.

## [3.5.0]

### Added
Expand Down
170 changes: 88 additions & 82 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "parity-scale-codec"
description = "SCALE - Simple Concatenating Aggregated Little Endians"
version = "3.5.0"
version = "3.6.0"
authors = ["Parity Technologies <admin@parity.io>"]
license = "Apache-2.0"
repository = "https://github.com/paritytech/parity-scale-codec"
Expand All @@ -12,7 +12,7 @@ rust-version = "1.60.0"
[dependencies]
arrayvec = { version = "0.7", default-features = false }
serde = { version = "1.0.164", optional = true }
parity-scale-codec-derive = { path = "derive", version = "3.1.4", default-features = false, optional = true }
parity-scale-codec-derive = { path = "derive", version = ">= 3.6.0", default-features = false, optional = true }
bitvec = { version = "1", default-features = false, features = [ "alloc" ], optional = true }
bytes = { version = "1", default-features = false, optional = true }
byte-slice-cast = { version = "1.2.2", default-features = false }
Expand All @@ -21,7 +21,7 @@ arbitrary = { version = "1.0.1", features = ["derive"], optional = true }
impl-trait-for-tuples = "0.2.2"

[dev-dependencies]
criterion = "0.3.0"
criterion = "0.4.0"
serde_derive = { version = "1.0" }
parity-scale-codec-derive = { path = "derive", default-features = false }
quickcheck = "1.0"
Expand All @@ -46,7 +46,7 @@ fuzz = ["std", "arbitrary"]
# Enables the new `MaxEncodedLen` trait.
# NOTE: This is still considered experimental and is exempt from the usual
# SemVer guarantees. We do not guarantee no code breakage when using this.
max-encoded-len = ["parity-scale-codec-derive/max-encoded-len"]
max-encoded-len = ["parity-scale-codec-derive?/max-encoded-len"]

# Make error fully descriptive with chaining error message.
# Should not be used in a constrained environment.
Expand Down
Loading

0 comments on commit 0688c04

Please sign in to comment.