View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0012172 | GNUnet | util library | public | 2026-11-18 10:22 | 2026-11-18 11:41 |
| Reporter | bot-cg [agent] | Assigned To | schanzen | ||
| Priority | normal | Severity | minor | Reproducibility | always |
| Status | resolved | Resolution | fixed | ||
| Product Version | Git master | ||||
| Target Version | 0.30.0 | Fixed in Version | 0.30.0 | ||
| Summary | 0012172: GNUNET_STRINGS_fancy_size_to_bytes: TB, PB and EB are off by a factor of 1.024 | ||||
| Description | The conversion table in src/lib/util/strings.c has { "TB", 1000LL * 1000LL * 1000LL * 1024LL }, { "PB", 1000LL * 1000LL * 1000LL * 1024LL * 1000LL }, { "EB", 1000LL * 1000LL * 1000LL * 1024LL * 1000LL * 1000LL }, so "1 TB" is 1024000000000 bytes rather than 10^12, and likewise for PB and EB. kB, MB and GB, and all the binary units, are right. GNUNET_CONFIGURATION_get_value_size inherits this. Found while testing a Go implementation of the GNUnet/Taler configuration format differentially against libgnunetutil at 57a93edc3. A patch with a regression test is attached; it is one of the series described in the parent issue. | ||||
| Steps To Reproduce | GNUNET_STRINGS_fancy_size_to_bytes ("1 TB", &size) sets size to 1024000000000. | ||||
| Additional Information | The attached patch uses powers of 1000 and adds checks to test_strings. No configuration file or string literal in the gnunet, exchange or merchant trees uses TB, PB or EB, and none of the other trees' configuration files does either. | ||||
| Tags | No tags attached. | ||||
| Attached Files | 0006-util-fix-the-factors-of-the-TB-PB-and-EB-size-units.patch (2,953 bytes)
From 23881fe9e236817911f6a21a256c88c5a43b55e4 Mon Sep 17 00:00:00 2001
From: Christian Grothoff <christian@grothoff.org>
Date: Wed, 18 Nov 2026 11:18:13 +0100
Subject: [PATCH 6/7] util: fix the factors of the TB, PB and EB size units
They were 1000^3 * 1024 and so on, so "1 TB" was 1.024 * 10^12 bytes.
Fixes #12172
Assisted by LLM
---
src/lib/util/strings.c | 6 +++---
src/lib/util/test_strings.c | 22 ++++++++++++++++++++++
2 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/src/lib/util/strings.c b/src/lib/util/strings.c
index 947fce766..2f70b6a3c 100644
--- a/src/lib/util/strings.c
+++ b/src/lib/util/strings.c
@@ -244,11 +244,11 @@ GNUNET_STRINGS_fancy_size_to_bytes (const char *fancy_size,
{ "GiB", 1024 * 1024 * 1024 },
{ "GB", 1000 * 1000 * 1000 },
{ "TiB", 1024LL * 1024LL * 1024LL * 1024LL },
- { "TB", 1000LL * 1000LL * 1000LL * 1024LL },
+ { "TB", 1000LL * 1000LL * 1000LL * 1000LL },
{ "PiB", 1024LL * 1024LL * 1024LL * 1024LL * 1024LL },
- { "PB", 1000LL * 1000LL * 1000LL * 1024LL * 1000LL },
+ { "PB", 1000LL * 1000LL * 1000LL * 1000LL * 1000LL },
{ "EiB", 1024LL * 1024LL * 1024LL * 1024LL * 1024LL * 1024LL },
- { "EB", 1000LL * 1000LL * 1000LL * 1024LL * 1000LL * 1000LL },
+ { "EB", 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL },
{ NULL, 0 } };
return convert_with_table (fancy_size, table, size);
diff --git a/src/lib/util/test_strings.c b/src/lib/util/test_strings.c
index 93d025612..cbf1af307 100644
--- a/src/lib/util/test_strings.c
+++ b/src/lib/util/test_strings.c
@@ -154,6 +154,28 @@ main (int argc, char *argv[])
GNUNET_STRINGS_fancy_time_to_relative ("15 m", &rtx));
GNUNET_assert (rt.rel_value_us == rtx.rel_value_us);
+ {
+ unsigned long long size;
+
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_STRINGS_fancy_size_to_bytes ("1 GB", &size));
+ GNUNET_assert (1000ULL * 1000ULL * 1000ULL == size);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_STRINGS_fancy_size_to_bytes ("1 TB", &size));
+ GNUNET_assert (1000ULL * 1000ULL * 1000ULL * 1000ULL == size);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_STRINGS_fancy_size_to_bytes ("2 PB", &size));
+ GNUNET_assert (2ULL * 1000ULL * 1000ULL * 1000ULL * 1000ULL * 1000ULL ==
+ size);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_STRINGS_fancy_size_to_bytes ("3 EB", &size));
+ GNUNET_assert (3ULL * 1000ULL * 1000ULL * 1000ULL * 1000ULL * 1000ULL
+ * 1000ULL == size);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_STRINGS_fancy_size_to_bytes ("1 TiB", &size));
+ GNUNET_assert (1ULL << 40 == size);
+ }
+
GNUNET_assert (0 != GNUNET_STRINGS_urlencode (strlen (
URLENCODE_TEST_VECTOR_PLAIN),
URLENCODE_TEST_VECTOR_PLAIN,
--
2.47.3
| ||||
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2026-11-18 10:22 | bot-cg | New Issue | |
| 2026-11-18 10:22 | bot-cg | Relationship added | child of 0012167 |
| 2026-11-18 10:23 | bot-cg | File Added: 0006-util-fix-the-factors-of-the-TB-PB-and-EB-size-units.patch | |
| 2026-11-18 11:07 | schanzen | Assigned To | => schanzen |
| 2026-11-18 11:07 | schanzen | Status | new => assigned |
| 2026-11-18 11:07 | schanzen | Target Version | => 0.30.0 |
| 2026-11-18 11:41 | schanzen | Status | assigned => resolved |
| 2026-11-18 11:41 | schanzen | Resolution | open => fixed |
| 2026-11-18 11:41 | schanzen | Fixed in Version | => 0.30.0 |
| 2026-11-18 11:41 | schanzen | Note Added: 0030573 |