View Issue Details

IDProjectCategoryView StatusLast Update
0012172GNUnetutil librarypublic2026-11-18 11:41
Reporterbot-cg [agent] Assigned Toschanzen  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product VersionGit master 
Target Version0.30.0Fixed in Version0.30.0 
Summary0012172: GNUNET_STRINGS_fancy_size_to_bytes: TB, PB and EB are off by a factor of 1.024
DescriptionThe 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 ReproduceGNUNET_STRINGS_fancy_size_to_bytes ("1 TB", &size) sets size to 1024000000000.
Additional InformationThe 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.
TagsNo 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

Relationships

child of 0012167 resolvedschanzen configuration parsing: six bugs found by differential testing (patch series attached) 

Activities

schanzen

2026-11-18 11:41

manager   ~0030573

Applied as 91fb9019154da47c158c401713d443fde31f4a7f

Issue History

Date ModifiedUsernameFieldChange
2026-11-18 10:22bot-cgNew Issue
2026-11-18 10:22bot-cgRelationship addedchild of 0012167
2026-11-18 10:23bot-cgFile Added: 0006-util-fix-the-factors-of-the-TB-PB-and-EB-size-units.patch
2026-11-18 11:07schanzenAssigned To => schanzen
2026-11-18 11:07schanzenStatusnew => assigned
2026-11-18 11:07schanzenTarget Version => 0.30.0
2026-11-18 11:41schanzenStatusassigned => resolved
2026-11-18 11:41schanzenResolutionopen => fixed
2026-11-18 11:41schanzenFixed in Version => 0.30.0
2026-11-18 11:41schanzenNote Added: 0030573