The exceptions thrown by the libstdc++
and libc++
standard libraries seems to differ for iostream errors. libstdc++ will output iostream error
while libc++ will output unspecified iostream_category error
. This means that the expected serialization messages i.e:
https://github.com/bitcoin/bitcoin/blob/64139803f1225dab26197a20314109d37fa87d5f/src/test/fuzz/process_message.cpp#L47-L50
don’t always work. For example on macOS:
0./autogen.sh
1CC=/usr/local/opt/llvm/bin/clang-10 CXX=/usr/local/opt/llvm/bin/clang-10 ./configure --enable-fuzz --with-sanitizers=address,fuzzer,undefined
2make -j8
3src/test/fuzz/process_message ../qa-assets/fuzz_seed_corpus/process_message
4... fuzz fuzz fuzz
5INFO: Seed: 3527492440
6INFO: Loaded 1 modules (866992 inline 8-bit counters): 866992 [0x1092eab28, 0x1093be5d8),
7INFO: Loaded 1 PC tables (866992 PCs): 866992 [0x1093be5d8,0x10a0f90d8),
8INFO: 2888 files found in ../qa-assets/fuzz_seed_corpus/process_message
9INFO: -max_len is not provided; libFuzzer will not generate inputs larger than 1016709 bytes
10INFO: seed corpus: files: 2888 min: 1b max: 1016709b total: 21650652b rss: 129Mb
11Unexpected exception when processing message type "tx": Unknown transaction optional data: unspecified iostream_category error
12Assertion failed: (false), function test_one_input, file test/fuzz/process_message.cpp, line 109.
The same difference can be observed on a Debian system, compiling with Clang and linking against either library. i.e:
0#include <iostream>
1#include <fstream>
2int main() {
3 std::ifstream file;
4 file.exceptions(file.failbit);
5 try {
6 file.open("Not there!");
7 }
8 catch (const std::ios_base::failure &e) {
9 std::cerr << e.what() << " " << e.code() << "\n.";
10 }
11}
0clang version 9.0.1-12
1Target: x86_64-pc-linux-gnu
2
3clang++ stream.cpp -o stream
4./stream
5basic_ios::clear: iostream error iostream:1
6
7# compile with libc++
8clang++ stream.cpp -stdlib=libc++ -o stream
9root@a1c752a65885:/# ./stream
10ios_base::clear: unspecified iostream_category error iostream:1