From 9df4c3a780ccf3e8abe001226e2554be27282699 Mon Sep 17 00:00:00 2001 From: Nicolas Mattia Date: Fri, 7 Aug 2026 11:36:56 +0200 Subject: [PATCH 01/10] feat: prettify bytes ourselves This drops the [pretty-bytes](https://crates.io/crates/pretty-bytes) dependency (last update 9 years ago). Instead we now make the bytes pretty ourselves. This cleans up our dependency graph and closes the following (low severity) vulnerability: https://github.com/advisories/GHSA-g98v-hv3f-hcfr --- Cargo.Bazel.toml.lock | 31 ---------------- Cargo.lock | 37 ++----------------- bazel/rust.MODULE.bazel | 4 -- rs/sns/integration_tests/BUILD.bazel | 2 - rs/sns/integration_tests/Cargo.toml | 1 - .../sns_governance_mem_test_canister.rs | 25 ++++++++++++- 6 files changed, 26 insertions(+), 74 deletions(-) diff --git a/Cargo.Bazel.toml.lock b/Cargo.Bazel.toml.lock index 7e18da510c5a..cbcf5fccdbfa 100644 --- a/Cargo.Bazel.toml.lock +++ b/Cargo.Bazel.toml.lock @@ -843,17 +843,6 @@ version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi 0.1.19", - "libc", - "winapi", -] - [[package]] name = "auto_impl" version = "1.1.0" @@ -3542,7 +3531,6 @@ dependencies = [ "pkg-config", "pprof", "predicates", - "pretty-bytes", "pretty_assertions", "priority-queue", "proc-macro2", @@ -5125,15 +5113,6 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - [[package]] name = "hermit-abi" version = "0.3.9" @@ -9352,16 +9331,6 @@ dependencies = [ "unicode-segmentation", ] -[[package]] -name = "pretty-bytes" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "009d6edd2c1dbf2e1c0cd48a2f7766e03498d49ada7109a01c6911815c685316" -dependencies = [ - "atty", - "getopts", -] - [[package]] name = "pretty_assertions" version = "1.4.0" diff --git a/Cargo.lock b/Cargo.lock index a135481aeee1..9f7db8e3326f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -882,17 +882,6 @@ dependencies = [ "x509-cert", ] -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi 0.1.19", - "libc", - "winapi", -] - [[package]] name = "auto_impl" version = "1.3.0" @@ -5596,15 +5585,6 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - [[package]] name = "hermit-abi" version = "0.5.2" @@ -13978,7 +13958,6 @@ dependencies = [ "maplit", "num-traits", "on_wire", - "pretty-bytes", "pretty_assertions", "proptest", "prost", @@ -16649,7 +16628,7 @@ version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3640c1c38b8e4e43584d8df18be5fc6b0aa314ce6ebf51b53313d4306cca8e46" dependencies = [ - "hermit-abi 0.5.2", + "hermit-abi", "libc", "windows-sys 0.61.2", ] @@ -18614,7 +18593,7 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91df4bbde75afed763b708b7eee1e8e7651e02d97f6d5dd763e89367e957b23b" dependencies = [ - "hermit-abi 0.5.2", + "hermit-abi", "libc", ] @@ -19775,7 +19754,7 @@ checksum = "5d0e4f59085d47d8241c88ead0f274e8a0cb551f3625263c05eb8dd897c34218" dependencies = [ "cfg-if", "concurrent-queue", - "hermit-abi 0.5.2", + "hermit-abi", "pin-project-lite", "rustix 1.1.4", "windows-sys 0.61.2", @@ -19947,16 +19926,6 @@ dependencies = [ "unicode-width 0.2.0", ] -[[package]] -name = "pretty-bytes" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "009d6edd2c1dbf2e1c0cd48a2f7766e03498d49ada7109a01c6911815c685316" -dependencies = [ - "atty", - "getopts", -] - [[package]] name = "pretty_assertions" version = "1.4.1" diff --git a/bazel/rust.MODULE.bazel b/bazel/rust.MODULE.bazel index 7fae89ff09f2..55a180c7c834 100644 --- a/bazel/rust.MODULE.bazel +++ b/bazel/rust.MODULE.bazel @@ -1209,10 +1209,6 @@ crate.spec( package = "predicates", version = "^3.1.2", ) -crate.spec( - package = "pretty-bytes", - version = "^0.2.2", -) crate.spec( package = "pretty_assertions", version = "^1.4.0", diff --git a/rs/sns/integration_tests/BUILD.bazel b/rs/sns/integration_tests/BUILD.bazel index a9e44189b7e0..d6f2dc79595f 100644 --- a/rs/sns/integration_tests/BUILD.bazel +++ b/rs/sns/integration_tests/BUILD.bazel @@ -37,7 +37,6 @@ BASE_DEPENDENCIES = [ "//rs/universal_canister/lib", "@crate_index//:candid", "@crate_index//:maplit", - "@crate_index//:pretty-bytes", "@crate_index//:proptest", "@crate_index//:prost", "@crate_index//:rand", @@ -123,7 +122,6 @@ rust_canister( "//rs/sns/governance", "//rs/types/base_types", "@crate_index//:ic-stable-structures", - "@crate_index//:pretty-bytes", "@crate_index//:prost", "@crate_index//:rand", ], diff --git a/rs/sns/integration_tests/Cargo.toml b/rs/sns/integration_tests/Cargo.toml index 7363377dcb27..7997b6d59b58 100644 --- a/rs/sns/integration_tests/Cargo.toml +++ b/rs/sns/integration_tests/Cargo.toml @@ -49,7 +49,6 @@ ic-nns-test-utils-golden-nns-state = { path = "../../nns/test_utils/golden_nns_s ic-universal-canister = { path = "../../universal_canister/lib" } icrc-ledger-types = { path = "../../../packages/icrc-ledger-types" } maplit = { workspace = true } -pretty-bytes = "0.2.2" proptest = { workspace = true } prost = { workspace = true } rand = { workspace = true } diff --git a/rs/sns/integration_tests/test_canisters/sns_governance_mem_test_canister.rs b/rs/sns/integration_tests/test_canisters/sns_governance_mem_test_canister.rs index 7f28cf4a83f9..5f11f0256da0 100644 --- a/rs/sns/integration_tests/test_canisters/sns_governance_mem_test_canister.rs +++ b/rs/sns/integration_tests/test_canisters/sns_governance_mem_test_canister.rs @@ -34,7 +34,6 @@ use ic_stable_structures::{ memory_manager::{MemoryId, MemoryManager, VirtualMemory}, }; use icrc_ledger_types::icrc1::account::Subaccount; -use pretty_bytes::converter; use rand::{RngCore, SeedableRng, rngs::StdRng}; use std::{cell::RefCell, collections::BTreeMap}; @@ -131,8 +130,30 @@ fn proposal_action_iterator() -> impl Iterator { /// Provide human readable String given a count of bytes. /// Ex: 4240000 -> "4.24 MB" +/// +/// Uses SI units (base 1000) and rounds to at most 2 decimal places, dropping +/// any trailing zeros (e.g. 4_000_000 -> "4 MB", not "4.00 MB"). fn pretty_bytes(bytes: usize) -> String { - converter::convert(bytes as f64) + const UNITS: [&str; 9] = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]; + + let bytes = bytes as f64; + if bytes < 1_f64 { + return format!("{} B", bytes); + } + + let delimiter = 1000_f64; + let exponent = std::cmp::min( + (bytes.ln() / delimiter.ln()).floor() as i32, + (UNITS.len() - 1) as i32, + ); + + // Round to 2 decimals, then re-parse to drop any trailing zeros. + let value = format!("{:.2}", bytes / delimiter.powi(exponent)) + .parse::() + .unwrap(); + let unit = UNITS[exponent as usize]; + + format!("{} {}", value, unit) } /// Create a vector of NeuronIds. This is an expensive enough operation to do From dd90b3410995225eab54ee3486dff75bd67ca07d Mon Sep 17 00:00:00 2001 From: IDX GitHub Automation Date: Fri, 7 Aug 2026 09:51:01 +0000 Subject: [PATCH 02/10] Automatically updated Cargo*.lock --- Cargo.Bazel.json.lock | 167 +----------------------------------------- 1 file changed, 1 insertion(+), 166 deletions(-) diff --git a/Cargo.Bazel.json.lock b/Cargo.Bazel.json.lock index 4dd03e5a8ac0..e1fe78aeb29b 100644 --- a/Cargo.Bazel.json.lock +++ b/Cargo.Bazel.json.lock @@ -1,5 +1,5 @@ { - "checksum": "c36aa7b484a384810bc7d713e52ef735c6b22b5958a89a9d4c1c231810d8272b", + "checksum": "4e5778c156eeee7c6e4d0b33531b4d414de7523464eea45ef598ba8b3dea3ae3", "crates": { "actix-codec 0.5.1": { "name": "actix-codec", @@ -4804,67 +4804,6 @@ ], "license_file": "LICENSE-APACHE" }, - "atty 0.2.14": { - "name": "atty", - "version": "0.2.14", - "package_url": "https://github.com/softprops/atty", - "repository": { - "Http": { - "url": "https://static.crates.io/crates/atty/0.2.14/download", - "sha256": "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" - } - }, - "targets": [ - { - "Library": { - "crate_name": "atty", - "crate_root": "src/lib.rs", - "srcs": { - "allow_empty": true, - "include": [ - "**/*.rs" - ] - } - } - } - ], - "library_target_name": "atty", - "common_attrs": { - "compile_data_glob": [ - "**" - ], - "deps": { - "common": [], - "selects": { - "cfg(target_os = \"hermit\")": [ - { - "id": "hermit-abi 0.1.19", - "target": "hermit_abi" - } - ], - "cfg(unix)": [ - { - "id": "libc 0.2.186", - "target": "libc" - } - ], - "cfg(windows)": [ - { - "id": "winapi 0.3.9", - "target": "winapi" - } - ] - } - }, - "edition": "2015", - "version": "0.2.14" - }, - "license": "MIT", - "license_ids": [ - "MIT" - ], - "license_file": "LICENSE" - }, "auto_impl 1.1.0": { "name": "auto_impl", "version": "1.1.0", @@ -20860,10 +20799,6 @@ "id": "predicates 3.1.2", "target": "predicates" }, - { - "id": "pretty-bytes 0.2.2", - "target": "pretty_bytes" - }, { "id": "pretty_assertions 1.4.0", "target": "pretty_assertions" @@ -30186,54 +30121,6 @@ ], "license_file": "LICENSE-APACHE" }, - "hermit-abi 0.1.19": { - "name": "hermit-abi", - "version": "0.1.19", - "package_url": "https://github.com/hermitcore/libhermit-rs", - "repository": { - "Http": { - "url": "https://static.crates.io/crates/hermit-abi/0.1.19/download", - "sha256": "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" - } - }, - "targets": [ - { - "Library": { - "crate_name": "hermit_abi", - "crate_root": "src/lib.rs", - "srcs": { - "allow_empty": true, - "include": [ - "**/*.rs" - ] - } - } - } - ], - "library_target_name": "hermit_abi", - "common_attrs": { - "compile_data_glob": [ - "**" - ], - "deps": { - "common": [ - { - "id": "libc 0.2.186", - "target": "libc" - } - ], - "selects": {} - }, - "edition": "2018", - "version": "0.1.19" - }, - "license": "MIT/Apache-2.0", - "license_ids": [ - "Apache-2.0", - "MIT" - ], - "license_file": "LICENSE-APACHE" - }, "hermit-abi 0.3.9": { "name": "hermit-abi", "version": "0.3.9", @@ -55452,57 +55339,6 @@ ], "license_file": "LICENSE" }, - "pretty-bytes 0.2.2": { - "name": "pretty-bytes", - "version": "0.2.2", - "package_url": "https://github.com/banyan/rust-pretty-bytes", - "repository": { - "Http": { - "url": "https://static.crates.io/crates/pretty-bytes/0.2.2/download", - "sha256": "009d6edd2c1dbf2e1c0cd48a2f7766e03498d49ada7109a01c6911815c685316" - } - }, - "targets": [ - { - "Library": { - "crate_name": "pretty_bytes", - "crate_root": "src/lib.rs", - "srcs": { - "allow_empty": true, - "include": [ - "**/*.rs" - ] - } - } - } - ], - "library_target_name": "pretty_bytes", - "common_attrs": { - "compile_data_glob": [ - "**" - ], - "deps": { - "common": [ - { - "id": "atty 0.2.14", - "target": "atty" - }, - { - "id": "getopts 0.2.24", - "target": "getopts" - } - ], - "selects": {} - }, - "edition": "2015", - "version": "0.2.2" - }, - "license": "MIT", - "license_ids": [ - "MIT" - ], - "license_file": null - }, "pretty_assertions 1.4.0": { "name": "pretty_assertions", "version": "1.4.0", @@ -93358,7 +93194,6 @@ "pkg-config 0.3.32", "pprof 0.15.0", "predicates 3.1.2", - "pretty-bytes 0.2.2", "pretty_assertions 1.4.0", "priority-queue 1.3.2", "proc-macro2 1.0.106", From 46d1fa55c33d6e7af7aa4026b190f7aef70f6580 Mon Sep 17 00:00:00 2001 From: IDX GitHub Automation Date: Fri, 7 Aug 2026 13:53:29 +0000 Subject: [PATCH 03/10] Automatically updated Cargo*.lock --- Cargo.Bazel.json.lock | 167 +----------------------------------------- 1 file changed, 1 insertion(+), 166 deletions(-) diff --git a/Cargo.Bazel.json.lock b/Cargo.Bazel.json.lock index 81169cc97381..4a9bcd527352 100644 --- a/Cargo.Bazel.json.lock +++ b/Cargo.Bazel.json.lock @@ -1,5 +1,5 @@ { - "checksum": "647170affacac693377b15401dd1ebc9e641c21437d8afe01196df78bff56371", + "checksum": "c9854913eb63ba7ac7e515e9af0318c015df3e4ffabebdfc045f84d09116f725", "crates": { "actix-codec 0.5.1": { "name": "actix-codec", @@ -4804,67 +4804,6 @@ ], "license_file": "LICENSE-APACHE" }, - "atty 0.2.14": { - "name": "atty", - "version": "0.2.14", - "package_url": "https://github.com/softprops/atty", - "repository": { - "Http": { - "url": "https://static.crates.io/crates/atty/0.2.14/download", - "sha256": "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" - } - }, - "targets": [ - { - "Library": { - "crate_name": "atty", - "crate_root": "src/lib.rs", - "srcs": { - "allow_empty": true, - "include": [ - "**/*.rs" - ] - } - } - } - ], - "library_target_name": "atty", - "common_attrs": { - "compile_data_glob": [ - "**" - ], - "deps": { - "common": [], - "selects": { - "cfg(target_os = \"hermit\")": [ - { - "id": "hermit-abi 0.1.19", - "target": "hermit_abi" - } - ], - "cfg(unix)": [ - { - "id": "libc 0.2.186", - "target": "libc" - } - ], - "cfg(windows)": [ - { - "id": "winapi 0.3.9", - "target": "winapi" - } - ] - } - }, - "edition": "2015", - "version": "0.2.14" - }, - "license": "MIT", - "license_ids": [ - "MIT" - ], - "license_file": "LICENSE" - }, "auto_impl 1.1.0": { "name": "auto_impl", "version": "1.1.0", @@ -20823,10 +20762,6 @@ "id": "predicates 3.1.2", "target": "predicates" }, - { - "id": "pretty-bytes 0.2.2", - "target": "pretty_bytes" - }, { "id": "pretty_assertions 1.4.0", "target": "pretty_assertions" @@ -30208,54 +30143,6 @@ ], "license_file": "LICENSE-APACHE" }, - "hermit-abi 0.1.19": { - "name": "hermit-abi", - "version": "0.1.19", - "package_url": "https://github.com/hermitcore/libhermit-rs", - "repository": { - "Http": { - "url": "https://static.crates.io/crates/hermit-abi/0.1.19/download", - "sha256": "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" - } - }, - "targets": [ - { - "Library": { - "crate_name": "hermit_abi", - "crate_root": "src/lib.rs", - "srcs": { - "allow_empty": true, - "include": [ - "**/*.rs" - ] - } - } - } - ], - "library_target_name": "hermit_abi", - "common_attrs": { - "compile_data_glob": [ - "**" - ], - "deps": { - "common": [ - { - "id": "libc 0.2.186", - "target": "libc" - } - ], - "selects": {} - }, - "edition": "2018", - "version": "0.1.19" - }, - "license": "MIT/Apache-2.0", - "license_ids": [ - "Apache-2.0", - "MIT" - ], - "license_file": "LICENSE-APACHE" - }, "hermit-abi 0.3.9": { "name": "hermit-abi", "version": "0.3.9", @@ -55665,57 +55552,6 @@ ], "license_file": "LICENSE" }, - "pretty-bytes 0.2.2": { - "name": "pretty-bytes", - "version": "0.2.2", - "package_url": "https://github.com/banyan/rust-pretty-bytes", - "repository": { - "Http": { - "url": "https://static.crates.io/crates/pretty-bytes/0.2.2/download", - "sha256": "009d6edd2c1dbf2e1c0cd48a2f7766e03498d49ada7109a01c6911815c685316" - } - }, - "targets": [ - { - "Library": { - "crate_name": "pretty_bytes", - "crate_root": "src/lib.rs", - "srcs": { - "allow_empty": true, - "include": [ - "**/*.rs" - ] - } - } - } - ], - "library_target_name": "pretty_bytes", - "common_attrs": { - "compile_data_glob": [ - "**" - ], - "deps": { - "common": [ - { - "id": "atty 0.2.14", - "target": "atty" - }, - { - "id": "getopts 0.2.24", - "target": "getopts" - } - ], - "selects": {} - }, - "edition": "2015", - "version": "0.2.2" - }, - "license": "MIT", - "license_ids": [ - "MIT" - ], - "license_file": null - }, "pretty_assertions 1.4.0": { "name": "pretty_assertions", "version": "1.4.0", @@ -93753,7 +93589,6 @@ "pkg-config 0.3.32", "pprof 0.15.0", "predicates 3.1.2", - "pretty-bytes 0.2.2", "pretty_assertions 1.4.0", "priority-queue 1.3.2", "proc-macro2 1.0.106", From adceb83d84a45c4f520ae250fb24095b6347f660 Mon Sep 17 00:00:00 2001 From: IDX GitHub Automation Date: Fri, 7 Aug 2026 15:48:15 +0000 Subject: [PATCH 04/10] Automatically updated Cargo*.lock --- Cargo.Bazel.json.lock | 167 +----------------------------------------- 1 file changed, 1 insertion(+), 166 deletions(-) diff --git a/Cargo.Bazel.json.lock b/Cargo.Bazel.json.lock index b2e413a8a6dd..c0b8e2675ecf 100644 --- a/Cargo.Bazel.json.lock +++ b/Cargo.Bazel.json.lock @@ -1,5 +1,5 @@ { - "checksum": "0f17f4cd43f4bc4637280b8f3c8a6c297e4c0e266413471687c9acccedffcb61", + "checksum": "f5fa4925c2889dad8b9e769944efee74d6d541c611fc6723d1971160a87203d3", "crates": { "actix-codec 0.5.1": { "name": "actix-codec", @@ -4804,67 +4804,6 @@ ], "license_file": "LICENSE-APACHE" }, - "atty 0.2.14": { - "name": "atty", - "version": "0.2.14", - "package_url": "https://github.com/softprops/atty", - "repository": { - "Http": { - "url": "https://static.crates.io/crates/atty/0.2.14/download", - "sha256": "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" - } - }, - "targets": [ - { - "Library": { - "crate_name": "atty", - "crate_root": "src/lib.rs", - "srcs": { - "allow_empty": true, - "include": [ - "**/*.rs" - ] - } - } - } - ], - "library_target_name": "atty", - "common_attrs": { - "compile_data_glob": [ - "**" - ], - "deps": { - "common": [], - "selects": { - "cfg(target_os = \"hermit\")": [ - { - "id": "hermit-abi 0.1.19", - "target": "hermit_abi" - } - ], - "cfg(unix)": [ - { - "id": "libc 0.2.186", - "target": "libc" - } - ], - "cfg(windows)": [ - { - "id": "winapi 0.3.9", - "target": "winapi" - } - ] - } - }, - "edition": "2015", - "version": "0.2.14" - }, - "license": "MIT", - "license_ids": [ - "MIT" - ], - "license_file": "LICENSE" - }, "auto_impl 1.1.0": { "name": "auto_impl", "version": "1.1.0", @@ -20823,10 +20762,6 @@ "id": "predicates 3.1.2", "target": "predicates" }, - { - "id": "pretty-bytes 0.2.2", - "target": "pretty_bytes" - }, { "id": "pretty_assertions 1.4.0", "target": "pretty_assertions" @@ -30208,54 +30143,6 @@ ], "license_file": "LICENSE-APACHE" }, - "hermit-abi 0.1.19": { - "name": "hermit-abi", - "version": "0.1.19", - "package_url": "https://github.com/hermitcore/libhermit-rs", - "repository": { - "Http": { - "url": "https://static.crates.io/crates/hermit-abi/0.1.19/download", - "sha256": "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" - } - }, - "targets": [ - { - "Library": { - "crate_name": "hermit_abi", - "crate_root": "src/lib.rs", - "srcs": { - "allow_empty": true, - "include": [ - "**/*.rs" - ] - } - } - } - ], - "library_target_name": "hermit_abi", - "common_attrs": { - "compile_data_glob": [ - "**" - ], - "deps": { - "common": [ - { - "id": "libc 0.2.186", - "target": "libc" - } - ], - "selects": {} - }, - "edition": "2018", - "version": "0.1.19" - }, - "license": "MIT/Apache-2.0", - "license_ids": [ - "Apache-2.0", - "MIT" - ], - "license_file": "LICENSE-APACHE" - }, "hermit-abi 0.3.9": { "name": "hermit-abi", "version": "0.3.9", @@ -55665,57 +55552,6 @@ ], "license_file": "LICENSE" }, - "pretty-bytes 0.2.2": { - "name": "pretty-bytes", - "version": "0.2.2", - "package_url": "https://github.com/banyan/rust-pretty-bytes", - "repository": { - "Http": { - "url": "https://static.crates.io/crates/pretty-bytes/0.2.2/download", - "sha256": "009d6edd2c1dbf2e1c0cd48a2f7766e03498d49ada7109a01c6911815c685316" - } - }, - "targets": [ - { - "Library": { - "crate_name": "pretty_bytes", - "crate_root": "src/lib.rs", - "srcs": { - "allow_empty": true, - "include": [ - "**/*.rs" - ] - } - } - } - ], - "library_target_name": "pretty_bytes", - "common_attrs": { - "compile_data_glob": [ - "**" - ], - "deps": { - "common": [ - { - "id": "atty 0.2.14", - "target": "atty" - }, - { - "id": "getopts 0.2.24", - "target": "getopts" - } - ], - "selects": {} - }, - "edition": "2015", - "version": "0.2.2" - }, - "license": "MIT", - "license_ids": [ - "MIT" - ], - "license_file": null - }, "pretty_assertions 1.4.0": { "name": "pretty_assertions", "version": "1.4.0", @@ -93759,7 +93595,6 @@ "pkg-config 0.3.32", "pprof 0.15.0", "predicates 3.1.2", - "pretty-bytes 0.2.2", "pretty_assertions 1.4.0", "priority-queue 1.3.2", "proc-macro2 1.0.106", From 3f63392cc953bdecfadbe116ff74705438da9e73 Mon Sep 17 00:00:00 2001 From: IDX GitHub Automation Date: Mon, 10 Aug 2026 09:30:29 +0000 Subject: [PATCH 05/10] Automatically updated Cargo*.lock --- Cargo.Bazel.json.lock | 167 +----------------------------------------- 1 file changed, 1 insertion(+), 166 deletions(-) diff --git a/Cargo.Bazel.json.lock b/Cargo.Bazel.json.lock index 48161b6cd408..f20884c0f152 100644 --- a/Cargo.Bazel.json.lock +++ b/Cargo.Bazel.json.lock @@ -1,5 +1,5 @@ { - "checksum": "514b2410f417ef8bc23d8a9183f220251a0f9281dbd404260ef66f9d8cfc661a", + "checksum": "3e83beee1cd35b788b84503779092f91ccdf17163ebf8b0716e9311d05c8722f", "crates": { "actix-codec 0.5.1": { "name": "actix-codec", @@ -4804,67 +4804,6 @@ ], "license_file": "LICENSE-APACHE" }, - "atty 0.2.14": { - "name": "atty", - "version": "0.2.14", - "package_url": "https://github.com/softprops/atty", - "repository": { - "Http": { - "url": "https://static.crates.io/crates/atty/0.2.14/download", - "sha256": "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" - } - }, - "targets": [ - { - "Library": { - "crate_name": "atty", - "crate_root": "src/lib.rs", - "srcs": { - "allow_empty": true, - "include": [ - "**/*.rs" - ] - } - } - } - ], - "library_target_name": "atty", - "common_attrs": { - "compile_data_glob": [ - "**" - ], - "deps": { - "common": [], - "selects": { - "cfg(target_os = \"hermit\")": [ - { - "id": "hermit-abi 0.1.19", - "target": "hermit_abi" - } - ], - "cfg(unix)": [ - { - "id": "libc 0.2.186", - "target": "libc" - } - ], - "cfg(windows)": [ - { - "id": "winapi 0.3.9", - "target": "winapi" - } - ] - } - }, - "edition": "2015", - "version": "0.2.14" - }, - "license": "MIT", - "license_ids": [ - "MIT" - ], - "license_file": "LICENSE" - }, "auto_impl 1.1.0": { "name": "auto_impl", "version": "1.1.0", @@ -20823,10 +20762,6 @@ "id": "predicates 3.1.2", "target": "predicates" }, - { - "id": "pretty-bytes 0.2.2", - "target": "pretty_bytes" - }, { "id": "pretty_assertions 1.4.0", "target": "pretty_assertions" @@ -30208,54 +30143,6 @@ ], "license_file": "LICENSE-APACHE" }, - "hermit-abi 0.1.19": { - "name": "hermit-abi", - "version": "0.1.19", - "package_url": "https://github.com/hermitcore/libhermit-rs", - "repository": { - "Http": { - "url": "https://static.crates.io/crates/hermit-abi/0.1.19/download", - "sha256": "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" - } - }, - "targets": [ - { - "Library": { - "crate_name": "hermit_abi", - "crate_root": "src/lib.rs", - "srcs": { - "allow_empty": true, - "include": [ - "**/*.rs" - ] - } - } - } - ], - "library_target_name": "hermit_abi", - "common_attrs": { - "compile_data_glob": [ - "**" - ], - "deps": { - "common": [ - { - "id": "libc 0.2.186", - "target": "libc" - } - ], - "selects": {} - }, - "edition": "2018", - "version": "0.1.19" - }, - "license": "MIT/Apache-2.0", - "license_ids": [ - "Apache-2.0", - "MIT" - ], - "license_file": "LICENSE-APACHE" - }, "hermit-abi 0.3.9": { "name": "hermit-abi", "version": "0.3.9", @@ -55669,57 +55556,6 @@ ], "license_file": "LICENSE" }, - "pretty-bytes 0.2.2": { - "name": "pretty-bytes", - "version": "0.2.2", - "package_url": "https://github.com/banyan/rust-pretty-bytes", - "repository": { - "Http": { - "url": "https://static.crates.io/crates/pretty-bytes/0.2.2/download", - "sha256": "009d6edd2c1dbf2e1c0cd48a2f7766e03498d49ada7109a01c6911815c685316" - } - }, - "targets": [ - { - "Library": { - "crate_name": "pretty_bytes", - "crate_root": "src/lib.rs", - "srcs": { - "allow_empty": true, - "include": [ - "**/*.rs" - ] - } - } - } - ], - "library_target_name": "pretty_bytes", - "common_attrs": { - "compile_data_glob": [ - "**" - ], - "deps": { - "common": [ - { - "id": "atty 0.2.14", - "target": "atty" - }, - { - "id": "getopts 0.2.24", - "target": "getopts" - } - ], - "selects": {} - }, - "edition": "2015", - "version": "0.2.2" - }, - "license": "MIT", - "license_ids": [ - "MIT" - ], - "license_file": null - }, "pretty_assertions 1.4.0": { "name": "pretty_assertions", "version": "1.4.0", @@ -93763,7 +93599,6 @@ "pkg-config 0.3.32", "pprof 0.15.0", "predicates 3.1.2", - "pretty-bytes 0.2.2", "pretty_assertions 1.4.0", "priority-queue 1.3.2", "proc-macro2 1.0.106", From b3cab29ccf6fadeecbf27b453d374456f15b17c4 Mon Sep 17 00:00:00 2001 From: IDX GitHub Automation Date: Mon, 10 Aug 2026 12:25:14 +0000 Subject: [PATCH 06/10] Automatically updated Cargo*.lock --- Cargo.Bazel.json.lock | 167 +----------------------------------------- 1 file changed, 1 insertion(+), 166 deletions(-) diff --git a/Cargo.Bazel.json.lock b/Cargo.Bazel.json.lock index b0ebb1c364ad..851065077296 100644 --- a/Cargo.Bazel.json.lock +++ b/Cargo.Bazel.json.lock @@ -1,5 +1,5 @@ { - "checksum": "97a9cd320431b891c4d7c4d2690ad10b3886460adea34efc6f00568501485396", + "checksum": "55f74516e681d67e1b5168ddc21e30c8ff4d6b63325ce78936bfac679a71291f", "crates": { "actix-codec 0.5.1": { "name": "actix-codec", @@ -4711,67 +4711,6 @@ ], "license_file": "LICENSE-APACHE" }, - "atty 0.2.14": { - "name": "atty", - "version": "0.2.14", - "package_url": "https://github.com/softprops/atty", - "repository": { - "Http": { - "url": "https://static.crates.io/crates/atty/0.2.14/download", - "sha256": "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" - } - }, - "targets": [ - { - "Library": { - "crate_name": "atty", - "crate_root": "src/lib.rs", - "srcs": { - "allow_empty": true, - "include": [ - "**/*.rs" - ] - } - } - } - ], - "library_target_name": "atty", - "common_attrs": { - "compile_data_glob": [ - "**" - ], - "deps": { - "common": [], - "selects": { - "cfg(target_os = \"hermit\")": [ - { - "id": "hermit-abi 0.1.19", - "target": "hermit_abi" - } - ], - "cfg(unix)": [ - { - "id": "libc 0.2.186", - "target": "libc" - } - ], - "cfg(windows)": [ - { - "id": "winapi 0.3.9", - "target": "winapi" - } - ] - } - }, - "edition": "2015", - "version": "0.2.14" - }, - "license": "MIT", - "license_ids": [ - "MIT" - ], - "license_file": "LICENSE" - }, "auto_impl 1.1.0": { "name": "auto_impl", "version": "1.1.0", @@ -20529,10 +20468,6 @@ "id": "predicates 3.1.2", "target": "predicates" }, - { - "id": "pretty-bytes 0.2.2", - "target": "pretty_bytes" - }, { "id": "pretty_assertions 1.4.0", "target": "pretty_assertions" @@ -29914,54 +29849,6 @@ ], "license_file": "LICENSE-APACHE" }, - "hermit-abi 0.1.19": { - "name": "hermit-abi", - "version": "0.1.19", - "package_url": "https://github.com/hermitcore/libhermit-rs", - "repository": { - "Http": { - "url": "https://static.crates.io/crates/hermit-abi/0.1.19/download", - "sha256": "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" - } - }, - "targets": [ - { - "Library": { - "crate_name": "hermit_abi", - "crate_root": "src/lib.rs", - "srcs": { - "allow_empty": true, - "include": [ - "**/*.rs" - ] - } - } - } - ], - "library_target_name": "hermit_abi", - "common_attrs": { - "compile_data_glob": [ - "**" - ], - "deps": { - "common": [ - { - "id": "libc 0.2.186", - "target": "libc" - } - ], - "selects": {} - }, - "edition": "2018", - "version": "0.1.19" - }, - "license": "MIT/Apache-2.0", - "license_ids": [ - "Apache-2.0", - "MIT" - ], - "license_file": "LICENSE-APACHE" - }, "hermit-abi 0.3.9": { "name": "hermit-abi", "version": "0.3.9", @@ -55375,57 +55262,6 @@ ], "license_file": "LICENSE" }, - "pretty-bytes 0.2.2": { - "name": "pretty-bytes", - "version": "0.2.2", - "package_url": "https://github.com/banyan/rust-pretty-bytes", - "repository": { - "Http": { - "url": "https://static.crates.io/crates/pretty-bytes/0.2.2/download", - "sha256": "009d6edd2c1dbf2e1c0cd48a2f7766e03498d49ada7109a01c6911815c685316" - } - }, - "targets": [ - { - "Library": { - "crate_name": "pretty_bytes", - "crate_root": "src/lib.rs", - "srcs": { - "allow_empty": true, - "include": [ - "**/*.rs" - ] - } - } - } - ], - "library_target_name": "pretty_bytes", - "common_attrs": { - "compile_data_glob": [ - "**" - ], - "deps": { - "common": [ - { - "id": "atty 0.2.14", - "target": "atty" - }, - { - "id": "getopts 0.2.24", - "target": "getopts" - } - ], - "selects": {} - }, - "edition": "2015", - "version": "0.2.2" - }, - "license": "MIT", - "license_ids": [ - "MIT" - ], - "license_file": null - }, "pretty_assertions 1.4.0": { "name": "pretty_assertions", "version": "1.4.0", @@ -93044,7 +92880,6 @@ "pkg-config 0.3.32", "pprof 0.15.0", "predicates 3.1.2", - "pretty-bytes 0.2.2", "pretty_assertions 1.4.0", "priority-queue 1.3.2", "proc-macro2 1.0.106", From 561b2fc05eb5f4de3904d421a7007d37203ba3a9 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 10 Aug 2026 14:55:15 +0000 Subject: [PATCH 07/10] review: address Daniel Wong's comments on pretty_bytes() - Check `bytes == 0` on the raw usize before casting to f64, and return "0 B" directly, instead of comparing the cast float to 1.0. - Comment the log-base-1000 exponent calculation (bytes.ln() / delimiter.ln()) as log10(bytes) / 3. - Replace the format!+parse:: round-trip for dropping trailing zeros with straightforward string trimming. --- .../sns_governance_mem_test_canister.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/rs/sns/integration_tests/test_canisters/sns_governance_mem_test_canister.rs b/rs/sns/integration_tests/test_canisters/sns_governance_mem_test_canister.rs index 5f11f0256da0..72f0d7751d69 100644 --- a/rs/sns/integration_tests/test_canisters/sns_governance_mem_test_canister.rs +++ b/rs/sns/integration_tests/test_canisters/sns_governance_mem_test_canister.rs @@ -136,21 +136,23 @@ fn proposal_action_iterator() -> impl Iterator { fn pretty_bytes(bytes: usize) -> String { const UNITS: [&str; 9] = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]; - let bytes = bytes as f64; - if bytes < 1_f64 { - return format!("{} B", bytes); + if bytes == 0 { + return "0 B".to_string(); } + let bytes = bytes as f64; let delimiter = 1000_f64; + // bytes.ln() / delimiter.ln() is log_1000(bytes), i.e. log10(bytes) / 3. let exponent = std::cmp::min( (bytes.ln() / delimiter.ln()).floor() as i32, (UNITS.len() - 1) as i32, ); - // Round to 2 decimals, then re-parse to drop any trailing zeros. + // Round to 2 decimals, then trim any trailing zeros and a trailing decimal point. let value = format!("{:.2}", bytes / delimiter.powi(exponent)) - .parse::() - .unwrap(); + .trim_end_matches('0') + .trim_end_matches('.'); + let unit = UNITS[exponent as usize]; format!("{} {}", value, unit) From 4b72adc149ee907d4d29b60bf811b1345d7bed81 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 10 Aug 2026 14:58:30 +0000 Subject: [PATCH 08/10] review: incorporate rationale comment from updated suggestion Daniel added an explanatory line to his zero-case suggestion after the initial review pass: 0_f64.ln() has no result mathematically, hence the early return for bytes == 0. Add that comment. --- .../test_canisters/sns_governance_mem_test_canister.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/rs/sns/integration_tests/test_canisters/sns_governance_mem_test_canister.rs b/rs/sns/integration_tests/test_canisters/sns_governance_mem_test_canister.rs index 72f0d7751d69..6a498548b125 100644 --- a/rs/sns/integration_tests/test_canisters/sns_governance_mem_test_canister.rs +++ b/rs/sns/integration_tests/test_canisters/sns_governance_mem_test_canister.rs @@ -136,6 +136,7 @@ fn proposal_action_iterator() -> impl Iterator { fn pretty_bytes(bytes: usize) -> String { const UNITS: [&str; 9] = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]; + // This avoids later doing 0_f64.ln(), which (in math) has NO result. if bytes == 0 { return "0 B".to_string(); } From fd2d869fc6d7614204a1b268c15db5928e142e38 Mon Sep 17 00:00:00 2001 From: IDX GitHub Automation Date: Mon, 10 Aug 2026 15:07:46 +0000 Subject: [PATCH 09/10] Automatically updated Cargo*.lock --- Cargo.Bazel.json.lock | 167 +----------------------------------------- 1 file changed, 1 insertion(+), 166 deletions(-) diff --git a/Cargo.Bazel.json.lock b/Cargo.Bazel.json.lock index 19308a0fea8d..61ac8fa0ccc5 100644 --- a/Cargo.Bazel.json.lock +++ b/Cargo.Bazel.json.lock @@ -1,5 +1,5 @@ { - "checksum": "d219ecf3003ae760b2a967cbf6532e80a278a2640cd74d57ab32af145fae636f", + "checksum": "5c79068fe3c1bb4d83af7406cb7b26fab7ec5aaaa978d05bdd40e2ba89e5d243", "crates": { "actix-codec 0.5.1": { "name": "actix-codec", @@ -4711,67 +4711,6 @@ ], "license_file": "LICENSE-APACHE" }, - "atty 0.2.14": { - "name": "atty", - "version": "0.2.14", - "package_url": "https://github.com/softprops/atty", - "repository": { - "Http": { - "url": "https://static.crates.io/crates/atty/0.2.14/download", - "sha256": "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" - } - }, - "targets": [ - { - "Library": { - "crate_name": "atty", - "crate_root": "src/lib.rs", - "srcs": { - "allow_empty": true, - "include": [ - "**/*.rs" - ] - } - } - } - ], - "library_target_name": "atty", - "common_attrs": { - "compile_data_glob": [ - "**" - ], - "deps": { - "common": [], - "selects": { - "cfg(target_os = \"hermit\")": [ - { - "id": "hermit-abi 0.1.19", - "target": "hermit_abi" - } - ], - "cfg(unix)": [ - { - "id": "libc 0.2.186", - "target": "libc" - } - ], - "cfg(windows)": [ - { - "id": "winapi 0.3.9", - "target": "winapi" - } - ] - } - }, - "edition": "2015", - "version": "0.2.14" - }, - "license": "MIT", - "license_ids": [ - "MIT" - ], - "license_file": "LICENSE" - }, "auto_impl 1.1.0": { "name": "auto_impl", "version": "1.1.0", @@ -20538,10 +20477,6 @@ "id": "predicates 3.1.2", "target": "predicates" }, - { - "id": "pretty-bytes 0.2.2", - "target": "pretty_bytes" - }, { "id": "pretty_assertions 1.4.0", "target": "pretty_assertions" @@ -29923,54 +29858,6 @@ ], "license_file": "LICENSE-APACHE" }, - "hermit-abi 0.1.19": { - "name": "hermit-abi", - "version": "0.1.19", - "package_url": "https://github.com/hermitcore/libhermit-rs", - "repository": { - "Http": { - "url": "https://static.crates.io/crates/hermit-abi/0.1.19/download", - "sha256": "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" - } - }, - "targets": [ - { - "Library": { - "crate_name": "hermit_abi", - "crate_root": "src/lib.rs", - "srcs": { - "allow_empty": true, - "include": [ - "**/*.rs" - ] - } - } - } - ], - "library_target_name": "hermit_abi", - "common_attrs": { - "compile_data_glob": [ - "**" - ], - "deps": { - "common": [ - { - "id": "libc 0.2.186", - "target": "libc" - } - ], - "selects": {} - }, - "edition": "2018", - "version": "0.1.19" - }, - "license": "MIT/Apache-2.0", - "license_ids": [ - "Apache-2.0", - "MIT" - ], - "license_file": "LICENSE-APACHE" - }, "hermit-abi 0.3.9": { "name": "hermit-abi", "version": "0.3.9", @@ -55384,57 +55271,6 @@ ], "license_file": "LICENSE" }, - "pretty-bytes 0.2.2": { - "name": "pretty-bytes", - "version": "0.2.2", - "package_url": "https://github.com/banyan/rust-pretty-bytes", - "repository": { - "Http": { - "url": "https://static.crates.io/crates/pretty-bytes/0.2.2/download", - "sha256": "009d6edd2c1dbf2e1c0cd48a2f7766e03498d49ada7109a01c6911815c685316" - } - }, - "targets": [ - { - "Library": { - "crate_name": "pretty_bytes", - "crate_root": "src/lib.rs", - "srcs": { - "allow_empty": true, - "include": [ - "**/*.rs" - ] - } - } - } - ], - "library_target_name": "pretty_bytes", - "common_attrs": { - "compile_data_glob": [ - "**" - ], - "deps": { - "common": [ - { - "id": "atty 0.2.14", - "target": "atty" - }, - { - "id": "getopts 0.2.24", - "target": "getopts" - } - ], - "selects": {} - }, - "edition": "2015", - "version": "0.2.2" - }, - "license": "MIT", - "license_ids": [ - "MIT" - ], - "license_file": null - }, "pretty_assertions 1.4.0": { "name": "pretty_assertions", "version": "1.4.0", @@ -93053,7 +92889,6 @@ "pkg-config 0.3.32", "pprof 0.15.0", "predicates 3.1.2", - "pretty-bytes 0.2.2", "pretty_assertions 1.4.0", "priority-queue 1.3.2", "proc-macro2 1.0.106", From 98d2d80d2dfc4ef0ef2b10a3d56d1986a4fac60d Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 10 Aug 2026 15:32:52 +0000 Subject: [PATCH 10/10] Fix E0716: temporary value dropped while borrowed in pretty_bytes() format!() produced a temporary String, and .trim_end_matches() returned a &str borrowing it; the temporary was dropped at the end of the statement while value was still used later. Bind the String to a name first, then shadow with the trimmed slice. --- .../test_canisters/sns_governance_mem_test_canister.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/rs/sns/integration_tests/test_canisters/sns_governance_mem_test_canister.rs b/rs/sns/integration_tests/test_canisters/sns_governance_mem_test_canister.rs index 6a498548b125..547bd08a05dc 100644 --- a/rs/sns/integration_tests/test_canisters/sns_governance_mem_test_canister.rs +++ b/rs/sns/integration_tests/test_canisters/sns_governance_mem_test_canister.rs @@ -150,9 +150,8 @@ fn pretty_bytes(bytes: usize) -> String { ); // Round to 2 decimals, then trim any trailing zeros and a trailing decimal point. - let value = format!("{:.2}", bytes / delimiter.powi(exponent)) - .trim_end_matches('0') - .trim_end_matches('.'); + let value = format!("{:.2}", bytes / delimiter.powi(exponent)); + let value = value.trim_end_matches('0').trim_end_matches('.'); let unit = UNITS[exponent as usize];