forked from denoland/deno
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ops): disallow memory slices as inputs to async ops (denoland#16738)
In Rust, it is UB if a slice is mutated while borrowed except through the slice itself, and it is also UB if a mutable slice is read while borrowed. The op macro allows borrowing an `ArrayBuffer{,View}` as a memory slice for the duration of an op, but this is not sound for async ops, since the `ArrayBuffer` could be accessed from JS during the await points. This PR therefore disallows such automatic borrowing only for async ops. Co-authored-by: Divy Srivastava <[email protected]>
- Loading branch information
1 parent
44d9acc
commit 90c0381
Showing
6 changed files
with
64 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
async fn op_read( | ||
async fn op_async_result( | ||
state: Rc<RefCell<OpState>>, | ||
rid: ResourceId, | ||
buf: &mut [u8], | ||
) -> Result<u32, Error> { | ||
// @test-attr:fast | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. | ||
|
||
use deno_ops::op; | ||
|
||
#[op] | ||
fn sync_test(slice: &mut [u32]) { | ||
// | ||
} | ||
|
||
#[op] | ||
async fn async_test(slice: &[u8]) { | ||
// Memory slices are not allowed in async ops. | ||
} | ||
|
||
#[op] | ||
fn async_test2(slice: &mut [u8]) -> impl Future<Output = ()> { | ||
// Memory slices are not allowed in async ops, even when not implemented as an | ||
// async function. | ||
async {} | ||
} | ||
|
||
fn main() { | ||
// pass | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error: custom attribute panicked | ||
--> tests/compile_fail/mem_slices.rs:10:1 | ||
| | ||
10 | #[op] | ||
| ^^^^^ | ||
| | ||
= help: message: Memory slices are not allowed in async ops | ||
|
||
error: custom attribute panicked | ||
--> tests/compile_fail/mem_slices.rs:15:1 | ||
| | ||
15 | #[op] | ||
| ^^^^^ | ||
| | ||
= help: message: Memory slices are not allowed in async ops |