Skip to content

Undefined behaviour in bench_dash #7011

Description

@OlegGirko

Expected behavior

./src/bench/bench_dash -sanity-check -priority-level=high successfully run to completion.

Actual behavior

Running with -sanity-check option, output is being suppressed as benchmark results will be useless.
/usr/include/c++/15/bits/stl_bvector.h:1158: constexpr std::vector<bool, _Alloc>::reference std::vector<bool, _Alloc>::operator[](size_type) [with _Alloc = std::allocator<bool>; reference = std::vector<bool>::reference; size_type = long unsigned int]: Assertion '__n < this->size()' failed.
Aborted                    (core dumped) ./src/bench/bench_dash -sanity-check -priority-level=high

To reproduce

Build bench_dash with GCC 15 and the following C++ flags:

-O2  -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64 -march=x86-64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -mtls-dialect=gnu2 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer

These are standard flags used to build packages for Fedora.

System information

Version 23.0.0 built from sources downloaded from Github.

Building on regular x86_64 PC running Fedora Linux 43.

The bug was introduces in commit 61bba13.

This line calls BuildTestVectors with first argument (count) equal to 1, but second argument (invalidCount) is still 10:

BuildTestVectors(bench.output() ? 1000 : 1, 10, pubKeys, secKeys, sigs, msgHashes, invalid);

As a result, invalid vector is resized to size 1 here:

invalid.resize(count);

and later out-of bound access is performed there:
invalid[i] = true;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions