diff options
| author | Leitwolf11 | 2026-11-17 19:00:44 +0300 |
|---|---|---|
| committer | Leitwolf11 | 2026-11-17 19:00:44 +0300 |
| commit | 7c3b73b14a3f0714c8eca3ad1a69bc1963ae773d (patch) | |
| tree | ff49cb6e7f90b671577993202249f207cfc99b6d | |
| parent | 7ff85d401d6f7f2d37fc0566f346a521a9bb7cee (diff) | |
| download | catch3-fix/pipe-read-limit.tar.gz | |
Ask read() for at most SSIZE_MAX bytes in PipeReader::Readfix/pipe-read-limit
POSIX leaves a read() request above SSIZE_MAX to the implementation, and
the count it returns could not then be told from an error. The POSIX
branch of PipeReader::Read now asks for the smaller of the buffer size and
SSIZE_MAX, as the Windows branch already limits one ReadFile call. The
caller sees no change: a short read was always possible, and the reader
loops until the pipe ends.
The single-file distribution is regenerated from the sources.
Checked: bazelisk test //... (3 of 3 pass), bazelisk run
//tools:amalgamate -- --check, clang-format dry-run with -Werror.
| -rw-r--r-- | extras/catch_amalgamated.cpp | 8 | ||||
| -rw-r--r-- | src/Progmasoft/Runner/Process.cpp | 8 |
2 files changed, 14 insertions, 2 deletions
diff --git a/extras/catch_amalgamated.cpp b/extras/catch_amalgamated.cpp index 475c5ea8..e09c8a56 100644 --- a/extras/catch_amalgamated.cpp +++ b/extras/catch_amalgamated.cpp @@ -15678,6 +15678,7 @@ namespace Progmasoft::Catch3::Runner #include <cstdlib> #include <cstring> #include <iterator> +#include <limits> #include <mutex> #include <string_view> #include <thread> @@ -16165,9 +16166,14 @@ namespace Progmasoft::Catch3::Runner } return static_cast<std::int64_t>(read); #else + // read() leaves a request above SSIZE_MAX to the implementation, so + // one call asks for at most that much and never more than the buffer. + const auto request = std::min<std::size_t>( + size, + static_cast<std::size_t>(std::numeric_limits<ssize_t>::max())); while (true) { - const auto count = read(Descriptor(handle_), buffer, size); + const auto count = read(Descriptor(handle_), buffer, request); if (count >= 0) { return static_cast<std::int64_t>(count); diff --git a/src/Progmasoft/Runner/Process.cpp b/src/Progmasoft/Runner/Process.cpp index 52c285e0..b81c121a 100644 --- a/src/Progmasoft/Runner/Process.cpp +++ b/src/Progmasoft/Runner/Process.cpp @@ -6,6 +6,7 @@ #include <cstdlib> #include <cstring> #include <iterator> +#include <limits> #include <mutex> #include <string_view> #include <thread> @@ -494,9 +495,14 @@ namespace Progmasoft::Catch3::Runner } return static_cast<std::int64_t>(read); #else + // read() leaves a request above SSIZE_MAX to the implementation, so + // one call asks for at most that much and never more than the buffer. + const auto request = std::min<std::size_t>( + size, + static_cast<std::size_t>(std::numeric_limits<ssize_t>::max())); while (true) { - const auto count = read(Descriptor(handle_), buffer, size); + const auto count = read(Descriptor(handle_), buffer, request); if (count >= 0) { return static_cast<std::int64_t>(count); |