UBSan warning when fuzzing abs64(…) #20135

issue practicalswift openend this issue on October 12, 2020
  1. practicalswift commented at 7:10 pm on October 12, 2020: contributor

    When extending the test/fuzz/integer fuzzer I noticed the following UBSan warning when fuzzing abs64(...):

    0runtime error: negation of -9223372036854775808 cannot be represented in type 'int64_t' (aka 'long'); cast to an unsigned type to negate this value to itself
    

    Fuzzing harness:

     0diff --git a/src/test/fuzz/integer.cpp b/src/test/fuzz/integer.cpp
     1index 35d6804d4..bc158e5a2 100644
     2--- a/src/test/fuzz/integer.cpp
     3+++ b/src/test/fuzz/integer.cpp
     4@@ -40,6 +40,8 @@
     5 #include <set>
     6 #include <vector>
     7
     8 void initialize()
     9 {
    10     SelectParams(CBaseChainParams::REGTEST);
    11@@ -82,6 +84,7 @@ void test_one_input(const std::vector<uint8_t>& buffer)
    12     (void)ComputeMerkleRoot(v256);
    13     (void)CountBits(u64);
    14     (void)DecompressAmount(u64);
    15+    (void)abs64(i64);
    16     (void)FormatISO8601Date(i64);
    17     (void)FormatISO8601DateTime(i64);
    18     // FormatMoney(i) not defined when i == std::numeric_limits<int64_t>::min()
    

    Typically abs(I n) type functions are not defined when n == std::numeric_limits<I>::min() so it could be argued that this is expected, but perhaps the function could be rewritten in a way which guarantees that it gives the same behaviour across systems (instead of UB).

  2. fanquake closed this on Oct 13, 2020

  3. fanquake closed this on Oct 13, 2020

  4. Fabcien referenced this in commit f61fd42904 on Nov 12, 2021
  5. DrahtBot locked this on Feb 15, 2022
  6. PastaPastaPasta referenced this in commit 5e63fcb792 on May 24, 2023
  7. PastaPastaPasta referenced this in commit b1d0a35d78 on May 29, 2023
  8. PastaPastaPasta referenced this in commit ee3953adb9 on May 29, 2023
  9. PastaPastaPasta referenced this in commit 1fdf76bfb6 on May 31, 2023


practicalswift


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-10-04 22:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me