Undefined behavior in AutoFile::write (gcc only) #28761

issue dergoegge opened this issue on October 31, 2023
  1. dergoegge commented at 1:03 PM on October 31, 2023: member
    $ CC=gcc CXX=g++ ./configure --with-sanitizers=undefined && make
    $ export UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1:report_error_type=1
    $ FUZZ=utxo_snapshot ./src/test/fuzz/fuzz ../qa-assets/fuzz_seed_corpus/utxo_snapshot/
    streams.cpp:48:24: runtime error: null pointer passed as argument 1, which is declared to never be null
        [#0](/bitcoin-bitcoin/0/) 0x5634737bcdc0 in AutoFile::write(Span<std::byte const>) src/streams.cpp:48
        [#1](/bitcoin-bitcoin/1/) 0x5634749e553b in void Serialize<AutoFile, unsigned char const>(AutoFile&, Span<unsigned char const>) serialize.h:288
        [#2](/bitcoin-bitcoin/2/) 0x5634749e553b in AutoFile& AutoFile::operator<< <Span<unsigned char const> >(Span<unsigned char const> const&) streams.h:527
        [#3](/bitcoin-bitcoin/3/) 0x5634749e553b in utxo_snapshot_fuzz_target test/fuzz/utxo_snapshot.cpp:45
        ...
    $ ./src/test/test_bitcoin --run_test="net_tests"
    streams.cpp:49:24: runtime error: null pointer passed as argument 1, which is declared to never be null
        [#0](/bitcoin-bitcoin/0/) 0x55613837a3ee in AutoFile::write(Span<std::byte const>) src/streams.cpp:49
        [#1](/bitcoin-bitcoin/1/) 0x55613b9747cc in void Serialize<AutoFile, unsigned char const>(AutoFile&, Span<unsigned char const>) serialize.h:288
        [#2](/bitcoin-bitcoin/2/) 0x55613b9747cc in AutoFile& AutoFile::operator<< <Span<unsigned char const> >(Span<unsigned char const> const&) streams.h:527
        [#3](/bitcoin-bitcoin/3/) 0x55613b9747cc in CaptureMessageToFile src/net.cpp:3885
    

    This is harmless since the spans passed to AutoFile::write will always be of size 0 in this case.

  2. maflcko commented at 4:49 PM on October 31, 2023: member

    I think this is a "bug" in gcc that should be fixed upstream. See also the related discussion in https://reviews.llvm.org/D86993

  3. maflcko added the label Upstream on Oct 31, 2023
  4. maflcko added the label Tests on Oct 31, 2023
  5. maflcko commented at 3:47 PM on November 2, 2023: member

    Also, a suppression can be added in the meantime, if anyone is using g++

  6. willcl-ark closed this on Oct 14, 2024

  7. bitcoin locked this on Oct 14, 2025

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 21:13 UTC

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