Skip to content

Commit 2e03cf9

Browse files
authored
fix: fix hazmat assertion error when using fsm io (#67)
use read_exact variants also in fsm io
1 parent d7e9c5f commit 2e03cf9

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ smallvec = "1"
2020
bytes = { version = "1" }
2121
futures-lite = { version = "2.3", optional = true }
2222
self_cell = { version = "1" }
23-
iroh-io = { version = "0.6.0", default-features = false, optional = true }
23+
iroh-io = { version = "0.6.2", default-features = false, optional = true }
2424
positioned-io = { version = "0.3.1", default-features = false }
2525
genawaiter = { version = "0.99.1", features = ["futures03"], optional = true }
2626
tokio = { version = "1", features = ["sync"], default-features = false, optional = true }
@@ -42,7 +42,7 @@ proptest = "1.0.0"
4242
rand = "0.8.5"
4343
criterion = "0.4.0"
4444
tempfile = "3.6.0"
45-
iroh-io = { version = "0.6.0" }
45+
iroh-io = { version = "0.6.2" }
4646
warp = "0.3.5"
4747
proc-macro2 = "1.0.66"
4848
test-strategy = "0.3.1"

src/io/fsm.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ impl<R: AsyncStreamReader> ResponseDecoder<R> {
430430
let this = &mut self.0;
431431
let data = this
432432
.encoded
433-
.read_bytes(size)
433+
.read_bytes_exact(size)
434434
.await
435435
.map_err(|e| DecodeError::maybe_leaf_not_found(e, start_chunk))?;
436436
let leaf_hash = this.stack.pop().unwrap();
@@ -482,7 +482,7 @@ where
482482
start_chunk, size, ..
483483
} => {
484484
let start = start_chunk.to_bytes();
485-
let bytes = data.read_at(start, size).await?;
485+
let bytes = data.read_exact_at(start, size).await?;
486486
encoded
487487
.write_bytes(bytes)
488488
.await
@@ -555,7 +555,7 @@ where
555555
} => {
556556
let expected = stack.pop().unwrap();
557557
let start = start_chunk.to_bytes();
558-
let bytes = data.read_at(start, size).await?;
558+
let bytes = data.read_exact_at(start, size).await?;
559559
let (actual, to_write) = if !ranges.is_all() {
560560
// we need to encode just a part of the data
561561
//
@@ -669,7 +669,7 @@ async fn outboard_impl(
669669
start_chunk,
670670
..
671671
} => {
672-
let buf = data.read_bytes(size).await?;
672+
let buf = data.read_bytes_exact(size).await?;
673673
let hash = hash_subtree(start_chunk.0, &buf, is_root);
674674
stack.push(hash);
675675
}
@@ -722,7 +722,7 @@ async fn outboard_post_order_impl(
722722
start_chunk,
723723
..
724724
} => {
725-
let buf = data.read_bytes(size).await?;
725+
let buf = data.read_bytes_exact(size).await?;
726726
let hash = hash_subtree(start_chunk.0, &buf, is_root);
727727
stack.push(hash);
728728
}
@@ -802,7 +802,9 @@ mod validate {
802802
if tree.blocks() == 1 {
803803
// special case for a tree that fits in one block / chunk group
804804
let mut data = data;
805-
let data = data.read_at(0, tree.size().try_into().unwrap()).await?;
805+
let data = data
806+
.read_exact_at(0, tree.size().try_into().unwrap())
807+
.await?;
806808
let actual = hash_subtree(0, &data, true);
807809
if actual == outboard.root() {
808810
co.yield_(Ok(ChunkNum(0)..tree.chunks())).await;
@@ -831,7 +833,7 @@ mod validate {
831833
is_root: bool,
832834
) -> io::Result<()> {
833835
let len = (range.end - range.start).try_into().unwrap();
834-
let data = self.data.read_at(range.start, len).await?;
836+
let data = self.data.read_exact_at(range.start, len).await?;
835837
// is_root is always false because the case of a single chunk group is handled before calling this function
836838
let actual = hash_subtree(ChunkNum::full_chunks(range.start).0, &data, is_root);
837839
if &actual == hash {

0 commit comments

Comments
 (0)