catchorg / Catch2

A modern, C++-native, test framework for unit-tests, TDD and BDD - using C++14, C++17 and later (C++11 support is in v2.x branch, and C++03 on the Catch1.x branch)
https://discord.gg/4CWS9zD
Boost Software License 1.0
18.74k stars 3.05k forks source link

[bug] Crash in String Matcher #2931

Open opmtk opened 1 week ago

opmtk commented 1 week ago

Describe the bug

The following

        try {
            std::string a{ "string" };
            std::string const expected{ "string" };
            REQUIRE_THAT(a, Matches(expected));
        }
        catch (std::exception const& e) {
            std::cerr << std::format("caught '{}'\n", e.what());
        }

works as expected. If I get a bigger expected string (e.g. ~110kByte) it crashes with

...
[ctest] due to a fatal error condition:
[ctest]   SIGSEGV - Segmentation violation signal

The problem is related to the Matches matcher - the following doesn't crash:

        // Catch2's matchers haven't support for string_view
        std::string const expected_str{ csv_data::CsvSV };

        try {
            std::string a{ "string" };
            REQUIRE_THAT(expected_str, Matches(a));
        }
        catch (std::exception const& e) {
            std::cerr << std::format("caught '{}'\n", e.what());
        }

Expected behavior I must not crash in that way, even I've a try/catch block/scope!

Reproduction steps

See above.

Platform information:

Additional context

horenmar commented 1 day ago

I can't reproduce this locally, nor on CE.

Are you sure that the segfault comes from the StringMatcher?