Skip to content

Commit 2619a2e

Browse files
committed
piecrust-uplink: support bytecheck integrity check of arguments
1 parent a3a669f commit 2619a2e

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

piecrust-uplink/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- Change `wrap_call` function to support `bytecheck`-based integrity check of arguments [#324]
13+
1014
## [0.10.0] - 2024-01-24
1115

1216
### Added
@@ -152,6 +156,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
152156
- First `piecrust-uplink` release
153157

154158
<!-- ISSUES -->
159+
[#324]: https://github.com/dusk-network/piecrust/issues/324
155160
[#301]: https://github.com/dusk-network/piecrust/issues/301
156161
[#271]: https://github.com/dusk-network/piecrust/issues/271
157162
[#268]: https://github.com/dusk-network/piecrust/issues/268

piecrust-uplink/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ edition = "2021"
1313
license = "MPL-2.0"
1414

1515
[dependencies]
16-
rkyv = { version = "0.7", default-features = false, features = ["size_32", "alloc"] }
16+
rkyv = { version = "0.7", default-features = false, features = ["size_32", "alloc", "validation"] }
1717
bytecheck = { version = "0.6", default-features = false }
1818
dlmalloc = { version = "0.2", optional = true, features = ["global"] }
1919

piecrust-uplink/src/abi/helpers.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ use rkyv::ser::serializers::{
1111
BufferScratch, BufferSerializer, CompositeSerializer,
1212
};
1313
use rkyv::ser::Serializer;
14-
use rkyv::{archived_root, Archive, Deserialize, Infallible, Serialize};
14+
use rkyv::validation::validators::DefaultValidator;
15+
use rkyv::{check_archived_root, Archive, Deserialize, Infallible, Serialize};
1516

1617
use crate::types::StandardBufSerializer;
1718

@@ -21,14 +22,16 @@ use crate::types::StandardBufSerializer;
2122
pub fn wrap_call<A, R, F>(arg_len: u32, f: F) -> u32
2223
where
2324
A: Archive,
24-
A::Archived: Deserialize<A, Infallible>,
25+
A::Archived: Deserialize<A, Infallible>
26+
+ for<'b> bytecheck::CheckBytes<DefaultValidator<'b>>,
2527
R: for<'a> Serialize<StandardBufSerializer<'a>>,
2628
F: Fn(A) -> R,
2729
{
2830
with_arg_buf(|buf| {
2931
let slice = &buf[..arg_len as usize];
3032

31-
let aa: &A::Archived = unsafe { archived_root::<A>(slice) };
33+
let aa: &A::Archived = check_archived_root::<A>(slice)
34+
.expect("Argument should correctly deserialize");
3235
let a: A = aa.deserialize(&mut Infallible).unwrap();
3336

3437
let ret = f(a);

0 commit comments

Comments
 (0)