Skip to content

Commit

Permalink
Merge pull request #100 from availproject/miguel/halborn_audit/re_hal_02
Browse files Browse the repository at this point in the history
Ensure `max_rows` & `max_cols` are power of 2
  • Loading branch information
fmiguelgarcia authored Jul 12, 2024
2 parents f10b958 + 4971104 commit 105b0eb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion kate/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "kate"
version = "0.9.1"
version = "0.9.2"
authors = ["Denis Ermolin <denis.ermolin@matic.network>"]
edition = "2021"
license = "Apache-2.0"
Expand Down
8 changes: 8 additions & 0 deletions kate/src/com.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ pub enum Error {
ExtendedGridDomainSizeInvalid(usize),
IndexOutOfRange,
ConversionFailed,
InvalidMaxRows,
InvalidMaxCols,
}

impl From<TryFromIntError> for Error {
Expand Down Expand Up @@ -227,6 +229,12 @@ pub fn get_block_dimensions<const CHUNK_SIZE: usize>(
let () = USizeSafeCastToU32::<CHUNK_SIZE>::OK;
let chunk_size_u32 = unsafe { NonZeroU32::new_unchecked(CHUNK_SIZE as u32) };

// SAFETY: `max_rows` and `max_cols` must be a power of 2.
// Otherwise block dimensions will be one row short, as the
// row count equals `total_cells / max_cols1`.
ensure!(max_rows.0.is_power_of_two(), Error::InvalidMaxRows);
ensure!(max_cols.0.is_power_of_two(), Error::InvalidMaxCols);

let max_block_dimensions =
BlockDimensions::new(max_rows, max_cols, chunk_size_u32).ok_or(Error::BlockTooBig)?;
let max_block_dimensions_size = max_block_dimensions.size();
Expand Down

0 comments on commit 105b0eb

Please sign in to comment.