Skip to content

Commit

Permalink
fix: unsealing restrictions and padding (#958)
Browse files Browse the repository at this point in the history
fix: unsealing restrictions and padding
  • Loading branch information
dignifiedquire committed Nov 27, 2019
2 parents ed3d65d + 8e3061a commit 4084eed
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
7 changes: 5 additions & 2 deletions filecoin-proofs/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,16 @@ pub fn get_unsealed_range<T: Into<PathBuf> + AsRef<Path>>(
porep_config.window_size_nodes,
);

let offset_padded: PaddedBytesAmount = UnpaddedBytesAmount::from(offset).into();
let num_bytes_padded: PaddedBytesAmount = num_bytes.into();

let unsealed = StackedDrg::<DefaultTreeHasher, DefaultPieceHasher>::extract_range(
&pp,
&replica_id,
&data,
Some(config),
offset.into(),
num_bytes.into(),
offset_padded.into(),
num_bytes_padded.into(),
)?;

let written = write_unpadded(&unsealed, &mut buf_writer, offset.into(), num_bytes.into())?;
Expand Down
6 changes: 6 additions & 0 deletions filecoin-proofs/src/types/bytes_amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ impl From<UnpaddedBytesAmount> for UnpaddedByteIndex {
}
}

impl From<UnpaddedByteIndex> for UnpaddedBytesAmount {
fn from(n: UnpaddedByteIndex) -> Self {
UnpaddedBytesAmount(n.0)
}
}

impl From<UnpaddedByteIndex> for u64 {
fn from(n: UnpaddedByteIndex) -> Self {
n.0
Expand Down
10 changes: 0 additions & 10 deletions storage-proofs/src/stacked/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,16 +472,6 @@ impl<'a, H: 'static + Hasher, G: 'static + Hasher> StackedDrg<'a, H, G> {
num_bytes: usize,
) -> Result<Vec<u8>> {
ensure!(offset + num_bytes <= data.len(), "Out of bounds");
ensure!(
offset % NODE_SIZE == 0,
"Invalid offset, must be a multiple of {}",
NODE_SIZE
);
ensure!(
num_bytes % NODE_SIZE == 0,
"Invalid num_bytes, must be a multiple of {}",
NODE_SIZE
);

// determine the first window needed to be decoded
let first_window_index = offset / pp.window_size_bytes();
Expand Down

0 comments on commit 4084eed

Please sign in to comment.