Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix edge case in const decoding #6

Merged
merged 2 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ repository = "https://github.com/kevinheavey/five8"

[workspace.dependencies]
five8 = { path = "crates/five8", version = "0.1.0" }
five8_const = { path = "crates/five8_const", version = "0.1.2" }
five8_const = { path = "crates/five8_const", version = "0.1.3" }
five8_core = { path = "crates/five8_core", version = "0.1.0" }
3 changes: 3 additions & 0 deletions crates/five8/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,7 @@ mod tests {
use crate::{decode_32, decode_64};
#[cfg(target_feature = "avx2")]
use core::array::from_fn;
use five8_const::{decode_32_const, decode_64_const};
use five8_core::{BASE58_ENCODED_32_MAX_LEN, BASE58_ENCODED_64_MAX_LEN};
#[cfg(not(miri))]
use prop::array::uniform32;
Expand Down Expand Up @@ -850,6 +851,7 @@ mod tests {
let mut decoded = [0u8; 32];
decode_32(encoded.as_bytes(), &mut decoded).unwrap();
assert_eq!(&decoded, bytes);
assert_eq!(&decode_32_const(encoded), bytes);
}

fn check_encode_decode_64(
Expand All @@ -864,6 +866,7 @@ mod tests {
let mut decoded = [0u8; 64];
decode_64(encoded.as_bytes(), &mut decoded).unwrap();
assert_eq!(&decoded, bytes);
assert_eq!(&decode_64_const(encoded), bytes);
}

fn encode_64_to_string(
Expand Down
4 changes: 4 additions & 0 deletions crates/five8_const/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [0.1.3] - 2024-07-30

Fix edge case in const decoding.

## [0.1.2] - 2024-07-30

Fix typo in README.md
Expand Down
2 changes: 1 addition & 1 deletion crates/five8_const/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "five8_const"
version = "0.1.2"
version = "0.1.3"
edition = "2021"
resolver = "2"
description = "Compile-time base58 decoding."
Expand Down
2 changes: 1 addition & 1 deletion crates/five8_const/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const fn base58_decode_after_be_convert_const<const N: usize>(
if leading_zero_cnt as usize > N {
return Err(DecodeError::OutputTooLong);
}
if encoded[leading_zero_cnt as usize] == b'1' {
if (leading_zero_cnt as usize) < N && encoded[leading_zero_cnt as usize] == b'1' {
return Err(DecodeError::OutputTooLong);
}
Ok(())
Expand Down
Loading