From 76105e6f9569cb94a4f5d0738a2ac3184c874dba Mon Sep 17 00:00:00 2001 From: tison Date: Wed, 10 Jun 2026 21:11:52 +0800 Subject: [PATCH 1/6] fix: handle parse rounding overflow --- bsize/src/parse.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bsize/src/parse.rs b/bsize/src/parse.rs index 6f95bd9..c47a2b5 100644 --- a/bsize/src/parse.rs +++ b/bsize/src/parse.rs @@ -149,7 +149,7 @@ fn parse_size(mut src: &[u8]) -> Result { state = ParseState::Integer; } else { if *b >= b'5' { - mantissa += 1; + mantissa = mantissa.checked_add(1).ok_or(ParseError::Overflow)?; } state = ParseState::IntegerOverflow; exponent += 1; @@ -164,7 +164,7 @@ fn parse_size(mut src: &[u8]) -> Result { exponent -= 1; } else { if *b >= b'5' { - mantissa += 1; + mantissa = mantissa.checked_add(1).ok_or(ParseError::Overflow)?; } state = ParseState::FractionOverflow; } @@ -307,6 +307,8 @@ mod tests { for input in [ "18_446_744_073_709_551_616", "18_446_744_073_709_551_620", + "18446744073709551615.5", + "184467440737095516155", "18.446_744_073_709_551_616 EB", "19EB", "16EiB", From c7678a1b70c5020c19889a249f29860fae7922f6 Mon Sep 17 00:00:00 2001 From: tison Date: Wed, 10 Jun 2026 21:12:42 +0800 Subject: [PATCH 2/6] fix: deserialize binary serde with native widths --- bsize/src/serde.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/bsize/src/serde.rs b/bsize/src/serde.rs index 1034c3c..b260f4f 100644 --- a/bsize/src/serde.rs +++ b/bsize/src/serde.rs @@ -40,7 +40,7 @@ macro_rules! impl_serialize { impl_serialize!(u8, u16, u32, u64, usize); macro_rules! impl_deserialize { - ($($ty:ty),* $(,)?) => { + ($($ty:ty => $deserialize:ident),* $(,)?) => { $( impl<'de> serde_core::Deserialize<'de> for BSize<$ty> { fn deserialize(de: D) -> Result @@ -100,7 +100,7 @@ macro_rules! impl_deserialize { if de.is_human_readable() { de.deserialize_any(Visitor) } else { - de.deserialize_u64(Visitor) + de.$deserialize(Visitor) } } } @@ -108,7 +108,13 @@ macro_rules! impl_deserialize { }; } -impl_deserialize!(u8, u16, u32, u64, usize); +impl_deserialize!( + u8 => deserialize_u8, + u16 => deserialize_u16, + u32 => deserialize_u32, + u64 => deserialize_u64, + usize => deserialize_u64, +); #[cfg(test)] mod tests { From a6a827da39e37ca502b92071ac9314f1a1224279 Mon Sep 17 00:00:00 2001 From: tison Date: Wed, 10 Jun 2026 21:13:12 +0800 Subject: [PATCH 3/6] test: cover all features in xtask --- xtask/src/main.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 94004b9..1e3738f 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -71,6 +71,7 @@ struct CommandTest { impl CommandTest { fn run(self) { run_command(make_test_cmd(self.no_capture, &[])); + run_command(make_test_all_features_cmd(self.no_capture)); } } @@ -147,6 +148,15 @@ fn make_test_cmd(no_capture: bool, features: &[&str]) -> StdCommand { cmd } +fn make_test_all_features_cmd(no_capture: bool) -> StdCommand { + let mut cmd = find_command("cargo"); + cmd.args(["test", "--workspace", "--all-features"]); + if no_capture { + cmd.args(["--", "--nocapture"]); + } + cmd +} + fn make_format_cmd(fix: bool) -> StdCommand { let mut cmd = find_command("cargo"); cmd.args(["+nightly", "fmt", "--all"]); From c7eeb55c39b89c8a13002258394f162316f16ada Mon Sep 17 00:00:00 2001 From: tison Date: Wed, 10 Jun 2026 21:13:47 +0800 Subject: [PATCH 4/6] chore: exclude build output from taplo --- taplo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/taplo.toml b/taplo.toml index 1cb0f3a..ebbb309 100644 --- a/taplo.toml +++ b/taplo.toml @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +exclude = ["target/**"] include = ["Cargo.toml", "**/*.toml"] [formatting] From c29cbc97900a48d34cd5324a5d7b61726925ac25 Mon Sep 17 00:00:00 2001 From: tison Date: Wed, 10 Jun 2026 21:15:52 +0800 Subject: [PATCH 5/6] ci: check no_std builds --- .github/workflows/ci.yml | 25 +++++++++++++++++++++++++ bsize/Cargo.toml | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d0e764e..67c70f2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -82,18 +82,43 @@ jobs: run: cargo x test --no-capture shell: bash + no_std: + name: Check no_std + needs: msrv + strategy: + matrix: + rust-version: ${{ fromJson(needs.msrv.outputs.rust-versions) }} + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v6 + - uses: Swatinem/rust-cache@v2 + - name: Delete rust-toolchain.toml + run: rm rust-toolchain.toml + - name: Install toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ matrix.rust-version }} + targets: thumbv7em-none-eabihf + - name: Check no_std + run: | + cargo check -p bsize --no-default-features --target thumbv7em-none-eabihf + cargo check -p bsize --all-features --target thumbv7em-none-eabihf + shell: bash + required: name: Required runs-on: ubuntu-24.04 if: ${{ always() }} needs: - check + - no_std - test steps: - name: Guardian run: | if [[ ! ( \ "${{ needs.check.result }}" == "success" \ + && "${{ needs.no_std.result }}" == "success" \ && "${{ needs.test.result }}" == "success" \ ) ]]; then echo "Required jobs haven't been completed successfully." diff --git a/bsize/Cargo.toml b/bsize/Cargo.toml index 888e9f7..53236da 100644 --- a/bsize/Cargo.toml +++ b/bsize/Cargo.toml @@ -37,7 +37,7 @@ default = [] serde = ["dep:serde_core"] [dependencies] -serde_core = { version = "1", optional = true } +serde_core = { version = "1", default-features = false, optional = true } [dev-dependencies] serde = { version = "1", features = ["derive"] } From 3a516fc3ec0cd65fbae1365924b3b1cd19565db0 Mon Sep 17 00:00:00 2001 From: tison Date: Wed, 10 Jun 2026 21:34:01 +0800 Subject: [PATCH 6/6] fixup Signed-off-by: tison --- bsize/src/serde.rs | 7 ++++++- xtask/src/main.rs | 13 ++----------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/bsize/src/serde.rs b/bsize/src/serde.rs index b260f4f..bccc4c7 100644 --- a/bsize/src/serde.rs +++ b/bsize/src/serde.rs @@ -113,9 +113,14 @@ impl_deserialize!( u16 => deserialize_u16, u32 => deserialize_u32, u64 => deserialize_u64, - usize => deserialize_u64, ); +#[cfg(target_pointer_width = "32")] +impl_deserialize!(usize => deserialize_u32); + +#[cfg(target_pointer_width = "64")] +impl_deserialize!(usize => deserialize_u64); + #[cfg(test)] mod tests { use serde::Deserialize; diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 1e3738f..937be94 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! An xtask binary for managing workspace tasks. +//! A binary for managing workspace tasks. use std::path::Path; use std::process::Command as StdCommand; @@ -71,7 +71,7 @@ struct CommandTest { impl CommandTest { fn run(self) { run_command(make_test_cmd(self.no_capture, &[])); - run_command(make_test_all_features_cmd(self.no_capture)); + run_command(make_test_cmd(self.no_capture, &["serde"])); } } @@ -148,15 +148,6 @@ fn make_test_cmd(no_capture: bool, features: &[&str]) -> StdCommand { cmd } -fn make_test_all_features_cmd(no_capture: bool) -> StdCommand { - let mut cmd = find_command("cargo"); - cmd.args(["test", "--workspace", "--all-features"]); - if no_capture { - cmd.args(["--", "--nocapture"]); - } - cmd -} - fn make_format_cmd(fix: bool) -> StdCommand { let mut cmd = find_command("cargo"); cmd.args(["+nightly", "fmt", "--all"]);