Skip to content

Conversation

@practicalswift
Copy link
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)

@DrahtBot
Copy link
Contributor

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

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.

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 44abf41 🏉

Show signature and timestamp

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 -

@maflcko maflcko merged commit d2d0a04 into bitcoin:master Mar 17, 2020
}
} else {
return j != 0 && i > std::numeric_limits<T>::max() / j;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why implement this from scratch? Could just use __builtin_mul_overflow?

Copy link
Contributor Author

@practicalswift practicalswift Mar 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

:)

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Mar 18, 2020
…eader, CFeeRate and various functions

44abf41 tests: Add fuzzing harness for various functions taking std::string as input (practicalswift)
d69145a tests: Add fuzzing harness for MultiplicationOverflow(...) (practicalswift)
7726f3b tests: Add fuzzing harness for CFeeRate (practicalswift)
0579a27 tests: Add fuzzing harness for CBlockHeader (practicalswift)
cb4eec1 tests: Add fuzzing harness for count_seconds(...) (practicalswift)

Pull request description:

  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)
  ```

ACKs for top commit:
  MarcoFalke:
    ACK 44abf41 🏉

Tree-SHA512: 2b382a7bc8efdcc6dd8b79f1637f194ecdca3e522c6618ae6c4b0bf6f86d2e79b1bb1c7160522083600616d1ed509b2f577f3a512ea3a7825a0a3794578d9d90
sidhujag pushed a commit to syscoin-core/syscoin that referenced this pull request Nov 10, 2020
…eader, CFeeRate and various functions

44abf41 tests: Add fuzzing harness for various functions taking std::string as input (practicalswift)
d69145a tests: Add fuzzing harness for MultiplicationOverflow(...) (practicalswift)
7726f3b tests: Add fuzzing harness for CFeeRate (practicalswift)
0579a27 tests: Add fuzzing harness for CBlockHeader (practicalswift)
cb4eec1 tests: Add fuzzing harness for count_seconds(...) (practicalswift)

Pull request description:

  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)
  ```

ACKs for top commit:
  MarcoFalke:
    ACK 44abf41 🏉

Tree-SHA512: 2b382a7bc8efdcc6dd8b79f1637f194ecdca3e522c6618ae6c4b0bf6f86d2e79b1bb1c7160522083600616d1ed509b2f577f3a512ea3a7825a0a3794578d9d90
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jan 20, 2021
…arious functions

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

Backport of core [[bitcoin/bitcoin#18353 | PR18353]].

The amount random generator and the feerate fuzzer have been slightly
adapted to match our codebase.

Test Plan:
  ninja bitcoin-fuzzers
  ./test/fuzz/test_runner.py <path_to_corpus>

Reviewers: #bitcoin_abc, PiRK

Reviewed By: #bitcoin_abc, PiRK

Differential Revision: https://reviews.bitcoinabc.org/D8967
@practicalswift practicalswift deleted the fuzzers-coverage branch April 10, 2021 19:40
kwvg added a commit to kwvg/dash that referenced this pull request Jul 6, 2022
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants