fuzz: libstdc++ vs libc++ iostream exception messages differ #18749

issue fanquake openend this issue on April 23, 2020
  1. fanquake commented at 11:21 am on April 23, 2020: member

    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
    

    cc @practicalswift

  2. fanquake added the label Tests on Apr 23, 2020
  3. MarcoFalke commented at 11:30 am on April 23, 2020: member
    The same issue should happen when running libFuzzer/honggfuzz on Windows
  4. laanwj commented at 1:58 pm on April 23, 2020: member
    This is one of the reasons I’m always nervous about matching on the exact text of error messages. Happy this is only in the fuzzer, at least.
  5. practicalswift commented at 9:15 am on April 24, 2020: contributor

    @fanquake The reason for the text matching was to mimic how it was done here:

    https://github.com/bitcoin/bitcoin/blob/c7e6b3b343e836ff41e9a8872187e0b24f13064d/src/net_processing.cpp#L3337-L3357

    Perhaps matching on the error message substring instead of the whole string in the fuzzing harness would solve the problem with different string prefixes? :)

  6. MarcoFalke commented at 11:53 am on April 24, 2020: member
    The matching was removed from master, so it can be removed from the fuzzer as well?
  7. practicalswift commented at 12:37 pm on April 24, 2020: contributor
    @MarcoFalke Sure! Fix submitted as #18757 :) @fanquake Thanks for the ping!
  8. MarcoFalke closed this on Apr 24, 2020

  9. DrahtBot locked this on Feb 15, 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: 2024-11-21 21:12 UTC

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