tests: Add fuzzing harnesses for classes CBlockHeader, CFeeRate and various functions #18353

pull practicalswift wants to merge 5 commits into bitcoin:master from practicalswift:fuzzers-coverage changing 7 files +289 −6
  1. practicalswift commented at 4:19 PM on March 15, 2020: contributor

    Add fuzzing harnesses for classes CBlockHeader, CFeeRate and various functions.

    To test this PR:

    $ make distclean
    $ ./autogen.sh
    $ CC=clang CXX=clang++ ./configure --enable-fuzz \
          --with-sanitizers=address,fuzzer,undefined
    $ make
    $ src/test/fuzz/block_header
    ^c (ctrl-c)
    $ src/test/fuzz/fee_rate
    ^c (ctrl-c)
    $ src/test/fuzz/integer
    ^c (ctrl-c)
    $ src/test/fuzz/multiplication_overflow
    ^c (ctrl-c)
    $ src/test/fuzz/string
    ^c (ctrl-c)
    
  2. tests: Add fuzzing harness for count_seconds(...) cb4eec13c0
  3. tests: Add fuzzing harness for CBlockHeader 0579a27630
  4. tests: Add fuzzing harness for CFeeRate 7726f3bc46
  5. tests: Add fuzzing harness for MultiplicationOverflow(...) d69145acb7
  6. tests: Add fuzzing harness for various functions taking std::string as input 44abf417eb
  7. DrahtBot added the label Build system on Mar 15, 2020
  8. DrahtBot added the label Tests on Mar 15, 2020
  9. practicalswift force-pushed on Mar 15, 2020
  10. DrahtBot commented at 7:13 PM on March 15, 2020: member

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #18155 (tests: Add harness which fuzzes EvalScript and VerifyScript using a fuzzed signature checker by practicalswift)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  11. fanquake removed the label Build system on Mar 15, 2020
  12. in src/test/fuzz/multiplication_overflow.cpp:21 in 44abf417eb
      16 | +{
      17 | +    const T i = fuzzed_data_provider.ConsumeIntegral<T>();
      18 | +    const T j = fuzzed_data_provider.ConsumeIntegral<T>();
      19 | +    const bool is_multiplication_overflow_custom = MultiplicationOverflow(i, j);
      20 | +    T result_builtin;
      21 | +    const bool is_multiplication_overflow_builtin = __builtin_mul_overflow(i, j, &result_builtin);
    


    MarcoFalke commented at 8:56 PM on March 16, 2020:

    does this compile for afl?


    practicalswift commented at 9:42 PM on March 16, 2020:

    Yes it should :) Let me know if you find any evidence to the contrary :)

  13. MarcoFalke commented at 8:57 PM on March 16, 2020: member

    ACK 44abf417eb1cd8598084eee1a429ca57c7d0579a 🏉

    <details><summary>Show signature and timestamp</summary>

    Signature:

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA512
    
    ACK 44abf417eb1cd8598084eee1a429ca57c7d0579a 🏉
    -----BEGIN PGP SIGNATURE-----
    
    iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
    pUhRiwv/bqyRTqalOU8zmulOw+CcCpymXv4nkrcWqw+p1GlsNoQd1ZlA+tSJve6f
    rsHCSx/TGpqMztqJ/5K1BW+FAjFtWKi0+s5EeQ1ah99281JcCUli2FgOeMUiH8oZ
    TZxZvsfkFojWgDn4PiACr9YjWsBCM0K/JKf44poHRaybF1IM+RI7W2lUR8CJMram
    sd5bXaw+3NG13KZCQvuRL7sShFlgizBcIFvch2VTH7Y+6y5VEqWt1ZVfWnXGE54U
    x0qPfh6KCbro4gPwAlovXBF/PmmT7FKwplDsI8rQt2a2p6QdN8+i65NWg/Wib9nB
    KXD4Mco1MYkl/QUlb92T1IramBqTdroI8lktcD6bsBns4u+fXGwVPCZJQ8LQcGYt
    xKit1zMn1N4L34ZG1qdTzMGeo+vCu+paXPvoZ8fNcBehelnNec+RtQTiGOjG7+Y/
    NMYnhSfMgFzMawX7HqE/lhs3F0YWUevoyUjrTkzQKymsHeY2m2ywaa6WRwFCXn8l
    iRkFevd/
    =b0BC
    -----END PGP SIGNATURE-----
    

    Timestamp of file with hash 0aac1971bcd3d59c21efc537215377f811eface51e1bcab3cac5dcd6d853c5b4 -

    </details>

  14. MarcoFalke merged this on Mar 17, 2020
  15. MarcoFalke closed this on Mar 17, 2020

  16. in src/test/fuzz/util.h:93 in 44abf417eb
      88 | +                return i != 0 && (j < (std::numeric_limits<T>::max() / i));
      89 | +            }
      90 | +        }
      91 | +    } else {
      92 | +        return j != 0 && i > std::numeric_limits<T>::max() / j;
      93 | +    }
    


    MarcoFalke commented at 5:15 PM on March 17, 2020:

    Why implement this from scratch? Could just use __builtin_mul_overflow?


    practicalswift commented at 5:45 PM on March 17, 2020:

    I think it would be handy to have MultiplicationOverflow(…) in other non-test parts of the code base.

    When we are confident of the equivalence between MultiplicationOverflow and __builtin_mul_overflow we can implement MultiplicationOverflow by using the __builtin_mul_overflow builtin where available (gcc + clang) and the current implementation where it is not (MSVC).

    That's why I added a fuzz test for MultiplicationOverflow too.

    And when we have a version of MultiplicationOverflow(…) that is known to be working on all platforms we can start using it in non-test code.

    Makes sense? :)


    practicalswift commented at 5:52 PM on March 17, 2020:

    When talking about integer overflows:

    Don't miss this one: a signed integer overflow in Microsoft's SafeInt ("SafeInt is a class library for C++ that manages integer overflows")...

    It's like rain on your wedding day It's a free ride when you've already paid It's the good advice that you just didn't take

    :)

  17. sidhujag referenced this in commit 6882b9909d on Mar 18, 2020
  18. sidhujag referenced this in commit 704826e71e on Nov 10, 2020
  19. deadalnix referenced this in commit 71ef71511c on Jan 20, 2021
  20. practicalswift deleted the branch on Apr 10, 2021
  21. kittywhiskers referenced this in commit be947af607 on May 7, 2022
  22. kittywhiskers referenced this in commit 89c6ba9dc3 on May 7, 2022
  23. kittywhiskers referenced this in commit bdea1ca7df on Jun 14, 2022
  24. kittywhiskers referenced this in commit 8877f85c48 on Jun 14, 2022
  25. kittywhiskers referenced this in commit af98eaf5e5 on Jun 18, 2022
  26. kittywhiskers referenced this in commit fc8bc96e3f on Jul 4, 2022
  27. kittywhiskers referenced this in commit f6d1874267 on Jul 4, 2022
  28. kittywhiskers referenced this in commit ab8822c184 on Jul 6, 2022
  29. PastaPastaPasta referenced this in commit eefdae1a53 on Jul 12, 2022
  30. knst referenced this in commit 896062c1d5 on Jul 21, 2022
  31. DrahtBot locked this on Aug 18, 2022

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: 2026-04-16 15:14 UTC

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