Skip to content

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

Closed

Description

@dergoegge
$ 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 0x5634737bcdc0 in AutoFile::write(Span<std::byte const>) src/streams.cpp:48
    #1 0x5634749e553b in void Serialize<AutoFile, unsigned char const>(AutoFile&, Span<unsigned char const>) serialize.h:288
    #2 0x5634749e553b in AutoFile& AutoFile::operator<< <Span<unsigned char const> >(Span<unsigned char const> const&) streams.h:527
    #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 0x55613837a3ee in AutoFile::write(Span<std::byte const>) src/streams.cpp:49
    #1 0x55613b9747cc in void Serialize<AutoFile, unsigned char const>(AutoFile&, Span<unsigned char const>) serialize.h:288
    #2 0x55613b9747cc in AutoFile& AutoFile::operator<< <Span<unsigned char const> >(Span<unsigned char const> const&) streams.h:527
    #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.

Activity

  1. maflcko commented on Oct 31, 2023

    @maflcko
    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

  2. maflcko commented on Nov 2, 2023

    @maflcko
    Member

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

  3. locked and limited conversation to collaborators on Oct 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions