Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Ask read() for at most SSIZE_MAX bytes in PipeReader::Read

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.
Commit
7c3b73b14a3f0714c8eca3ad1a69bc1963ae773d
Author
Leitwolf11 ·
Parents
7ff85d401d6f

Files · Download .tar.gz

Changes

 extras/catch_amalgamated.cpp      | 8 +++++++-
 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);