From 1b91a0e7e432eac5f8347a1b7505abed1f508f8c Mon Sep 17 00:00:00 2001 From: Nikolay Kalinin <6316472+KalininN@users.noreply.github.com> Date: Fri, 30 Jan 2026 15:34:23 +0100 Subject: [PATCH 1/5] Fixed #218 by introducing maxBlanksCount --- testlib.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/testlib.h b/testlib.h index 349b839..6060e19 100644 --- a/testlib.h +++ b/testlib.h @@ -2026,6 +2026,7 @@ struct InStream { int readManyIteration; size_t maxFileSize; size_t maxTokenLength; + size_t maxBlanksCount; size_t maxMessageLength; void init(std::string fileName, TMode mode); @@ -2844,6 +2845,7 @@ InStream::InStream() { readManyIteration = NO_INDEX; maxFileSize = 128 * 1024 * 1024; // 128MB. maxTokenLength = 32 * 1024 * 1024; // 32MB. + maxBlanksCount = 32 * 1024 * 1024; // 32MB. maxMessageLength = 32000; } @@ -3374,8 +3376,16 @@ void InStream::skipChar() { } void InStream::skipBlanks() { + size_t blanksCount = 0; while (isBlanks(reader->curChar())) + { + blanksCount++; + // You can change maxBlanksCount. + // Example: 'inf.maxBlanksCount = 128 * 1024 * 1024;'. + if (blanksCount > maxBlanksCount) + quit(_pe, "Too many white-space characters skipped"); reader->skipChar(); + } } std::string InStream::readWord() { From b0510387af43f327c9d2ecb470444baefa230ea6 Mon Sep 17 00:00:00 2001 From: Nikolay Kalinin <6316472+KalininN@users.noreply.github.com> Date: Fri, 30 Jan 2026 15:48:22 +0100 Subject: [PATCH 2/5] maxBlanksCount -> maxBlankCount, change log added --- testlib.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/testlib.h b/testlib.h index 6060e19..ec8da80 100644 --- a/testlib.h +++ b/testlib.h @@ -25,7 +25,7 @@ * Copyright (c) 2005-2025 */ -#define VERSION "0.9.45" +#define VERSION "0.9.45-SNAPSHOT" /* * Mike Mirzayanov @@ -63,6 +63,7 @@ */ const char *latestFeatures[] = { + "Added maxBlankCount to InStream to avoid infinite loops in skipBlanks()", "Remove incorrect const attributes", "Added ConstantBoundsLog, VariablesLog to validator testOverviewLogFile", "Use setAppesModeEncoding to change xml encoding from windows-1251 to other", @@ -2026,7 +2027,7 @@ struct InStream { int readManyIteration; size_t maxFileSize; size_t maxTokenLength; - size_t maxBlanksCount; + size_t maxBlankCount; size_t maxMessageLength; void init(std::string fileName, TMode mode); @@ -2845,7 +2846,7 @@ InStream::InStream() { readManyIteration = NO_INDEX; maxFileSize = 128 * 1024 * 1024; // 128MB. maxTokenLength = 32 * 1024 * 1024; // 32MB. - maxBlanksCount = 32 * 1024 * 1024; // 32MB. + maxBlankCount = 32 * 1024 * 1024; // 32MB. maxMessageLength = 32000; } @@ -3376,13 +3377,13 @@ void InStream::skipChar() { } void InStream::skipBlanks() { - size_t blanksCount = 0; + size_t blankCount = 0; while (isBlanks(reader->curChar())) { - blanksCount++; - // You can change maxBlanksCount. - // Example: 'inf.maxBlanksCount = 128 * 1024 * 1024;'. - if (blanksCount > maxBlanksCount) + blankCount++; + // You can change maxBlankCount. + // Example: 'inf.maxBlankCount = 32 * 1024 * 1024;'. + if (blankCount > maxBlankCount) quit(_pe, "Too many white-space characters skipped"); reader->skipChar(); } From 43d0e3f7f1fcd0204761f90f46344fe29e7c8875 Mon Sep 17 00:00:00 2001 From: Nikolay Kalinin <6316472+KalininN@users.noreply.github.com> Date: Fri, 30 Jan 2026 15:54:51 +0100 Subject: [PATCH 3/5] added maxBlankCount to the second constructor --- testlib.h | 1 + 1 file changed, 1 insertion(+) diff --git a/testlib.h b/testlib.h index ec8da80..69b650c 100644 --- a/testlib.h +++ b/testlib.h @@ -2861,6 +2861,7 @@ InStream::InStream(const InStream &baseStream, std::string content) { readManyIteration = NO_INDEX; maxFileSize = 128 * 1024 * 1024; // 128MB. maxTokenLength = 32 * 1024 * 1024; // 32MB. + maxBlankCount = 32 * 1024 * 1024; // 32MB. maxMessageLength = 32000; } From 712d13c80624abfe85fa84a5c6577b6ca04801f1 Mon Sep 17 00:00:00 2001 From: Nikolay Kalinin <6316472+KalininN@users.noreply.github.com> Date: Sat, 31 Jan 2026 09:07:42 +0100 Subject: [PATCH 4/5] better comment about maxBlankCount --- testlib.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testlib.h b/testlib.h index 69b650c..76badaa 100644 --- a/testlib.h +++ b/testlib.h @@ -3385,7 +3385,7 @@ void InStream::skipBlanks() { // You can change maxBlankCount. // Example: 'inf.maxBlankCount = 32 * 1024 * 1024;'. if (blankCount > maxBlankCount) - quit(_pe, "Too many white-space characters skipped"); + quitf(_pe, "Number of redundant consecutive white-space characters exceeds the limit (%d)", int(maxBlankCount)); reader->skipChar(); } } From b17f208525348baeab8f9e6287d31239afa3ff77 Mon Sep 17 00:00:00 2001 From: Niyaz Nigmatullin Date: Sat, 31 Jan 2026 10:37:04 +0200 Subject: [PATCH 5/5] Add interactor tests for maxBlankCount feature Includes new test cases for maxBlankCount functionality with normal and failure scenarios. Co-Authored-By: Claude Sonnet 4.5 --- .../files/unix/input.maxBlankCount | 4 +++ .../files/unix/participant.maxBlankCount.fail | 3 ++ .../unix/participant.maxBlankCount.normal | 3 ++ .../files/win/input.maxBlankCount | 4 +++ .../files/win/participant.maxBlankCount.fail | 3 ++ .../win/participant.maxBlankCount.normal | 3 ++ .../r-interactor-maxBlankCount-fail/exit_code | 1 + .../r-interactor-maxBlankCount-fail/stderr | 1 + .../r-interactor-maxBlankCount-fail/stdout | 1 + .../exit_code | 1 + .../stderr | 0 .../stdout | 3 ++ .../exit_code | 1 + .../r-interactor-maxBlankCount-normal/stderr | 1 + .../r-interactor-maxBlankCount-normal/stdout | 3 ++ tests/test-006_interactors/run.sh | 14 +++++++++ .../src/interactor-maxBlankCount.cpp | 30 +++++++++++++++++++ 17 files changed, 76 insertions(+) create mode 100644 tests/test-006_interactors/files/unix/input.maxBlankCount create mode 100644 tests/test-006_interactors/files/unix/participant.maxBlankCount.fail create mode 100644 tests/test-006_interactors/files/unix/participant.maxBlankCount.normal create mode 100644 tests/test-006_interactors/files/win/input.maxBlankCount create mode 100644 tests/test-006_interactors/files/win/participant.maxBlankCount.fail create mode 100644 tests/test-006_interactors/files/win/participant.maxBlankCount.normal create mode 100644 tests/test-006_interactors/refs/r-interactor-maxBlankCount-fail/exit_code create mode 100644 tests/test-006_interactors/refs/r-interactor-maxBlankCount-fail/stderr create mode 100644 tests/test-006_interactors/refs/r-interactor-maxBlankCount-fail/stdout create mode 100644 tests/test-006_interactors/refs/r-interactor-maxBlankCount-normal-output/exit_code create mode 100644 tests/test-006_interactors/refs/r-interactor-maxBlankCount-normal-output/stderr create mode 100644 tests/test-006_interactors/refs/r-interactor-maxBlankCount-normal-output/stdout create mode 100644 tests/test-006_interactors/refs/r-interactor-maxBlankCount-normal/exit_code create mode 100644 tests/test-006_interactors/refs/r-interactor-maxBlankCount-normal/stderr create mode 100644 tests/test-006_interactors/refs/r-interactor-maxBlankCount-normal/stdout create mode 100644 tests/test-006_interactors/src/interactor-maxBlankCount.cpp diff --git a/tests/test-006_interactors/files/unix/input.maxBlankCount b/tests/test-006_interactors/files/unix/input.maxBlankCount new file mode 100644 index 0000000..3f01f12 --- /dev/null +++ b/tests/test-006_interactors/files/unix/input.maxBlankCount @@ -0,0 +1,4 @@ +3 +10 +20 +30 diff --git a/tests/test-006_interactors/files/unix/participant.maxBlankCount.fail b/tests/test-006_interactors/files/unix/participant.maxBlankCount.fail new file mode 100644 index 0000000..2a9be51 --- /dev/null +++ b/tests/test-006_interactors/files/unix/participant.maxBlankCount.fail @@ -0,0 +1,3 @@ + 20 + 40 + 60 diff --git a/tests/test-006_interactors/files/unix/participant.maxBlankCount.normal b/tests/test-006_interactors/files/unix/participant.maxBlankCount.normal new file mode 100644 index 0000000..8b3995a --- /dev/null +++ b/tests/test-006_interactors/files/unix/participant.maxBlankCount.normal @@ -0,0 +1,3 @@ +20 +40 +60 diff --git a/tests/test-006_interactors/files/win/input.maxBlankCount b/tests/test-006_interactors/files/win/input.maxBlankCount new file mode 100644 index 0000000..3f01f12 --- /dev/null +++ b/tests/test-006_interactors/files/win/input.maxBlankCount @@ -0,0 +1,4 @@ +3 +10 +20 +30 diff --git a/tests/test-006_interactors/files/win/participant.maxBlankCount.fail b/tests/test-006_interactors/files/win/participant.maxBlankCount.fail new file mode 100644 index 0000000..b836a6d --- /dev/null +++ b/tests/test-006_interactors/files/win/participant.maxBlankCount.fail @@ -0,0 +1,3 @@ + 20 + 40 + 60 diff --git a/tests/test-006_interactors/files/win/participant.maxBlankCount.normal b/tests/test-006_interactors/files/win/participant.maxBlankCount.normal new file mode 100644 index 0000000..8b3995a --- /dev/null +++ b/tests/test-006_interactors/files/win/participant.maxBlankCount.normal @@ -0,0 +1,3 @@ +20 +40 +60 diff --git a/tests/test-006_interactors/refs/r-interactor-maxBlankCount-fail/exit_code b/tests/test-006_interactors/refs/r-interactor-maxBlankCount-fail/exit_code new file mode 100644 index 0000000..78c6bae --- /dev/null +++ b/tests/test-006_interactors/refs/r-interactor-maxBlankCount-fail/exit_code @@ -0,0 +1 @@ +2 diff --git a/tests/test-006_interactors/refs/r-interactor-maxBlankCount-fail/stderr b/tests/test-006_interactors/refs/r-interactor-maxBlankCount-fail/stderr new file mode 100644 index 0000000..50b0223 --- /dev/null +++ b/tests/test-006_interactors/refs/r-interactor-maxBlankCount-fail/stderr @@ -0,0 +1 @@ +wrong output format Number of redundant consecutive white-space characters exceeds the limit (1000) diff --git a/tests/test-006_interactors/refs/r-interactor-maxBlankCount-fail/stdout b/tests/test-006_interactors/refs/r-interactor-maxBlankCount-fail/stdout new file mode 100644 index 0000000..f599e28 --- /dev/null +++ b/tests/test-006_interactors/refs/r-interactor-maxBlankCount-fail/stdout @@ -0,0 +1 @@ +10 diff --git a/tests/test-006_interactors/refs/r-interactor-maxBlankCount-normal-output/exit_code b/tests/test-006_interactors/refs/r-interactor-maxBlankCount-normal-output/exit_code new file mode 100644 index 0000000..1874828 --- /dev/null +++ b/tests/test-006_interactors/refs/r-interactor-maxBlankCount-normal-output/exit_code @@ -0,0 +1 @@ +0 diff --git a/tests/test-006_interactors/refs/r-interactor-maxBlankCount-normal-output/stderr b/tests/test-006_interactors/refs/r-interactor-maxBlankCount-normal-output/stderr new file mode 100644 index 0000000..e69de29 diff --git a/tests/test-006_interactors/refs/r-interactor-maxBlankCount-normal-output/stdout b/tests/test-006_interactors/refs/r-interactor-maxBlankCount-normal-output/stdout new file mode 100644 index 0000000..8b3995a --- /dev/null +++ b/tests/test-006_interactors/refs/r-interactor-maxBlankCount-normal-output/stdout @@ -0,0 +1,3 @@ +20 +40 +60 diff --git a/tests/test-006_interactors/refs/r-interactor-maxBlankCount-normal/exit_code b/tests/test-006_interactors/refs/r-interactor-maxBlankCount-normal/exit_code new file mode 100644 index 0000000..573541a --- /dev/null +++ b/tests/test-006_interactors/refs/r-interactor-maxBlankCount-normal/exit_code @@ -0,0 +1 @@ +0 diff --git a/tests/test-006_interactors/refs/r-interactor-maxBlankCount-normal/stderr b/tests/test-006_interactors/refs/r-interactor-maxBlankCount-normal/stderr new file mode 100644 index 0000000..527a442 --- /dev/null +++ b/tests/test-006_interactors/refs/r-interactor-maxBlankCount-normal/stderr @@ -0,0 +1 @@ +ok 3 queries processed diff --git a/tests/test-006_interactors/refs/r-interactor-maxBlankCount-normal/stdout b/tests/test-006_interactors/refs/r-interactor-maxBlankCount-normal/stdout new file mode 100644 index 0000000..300ed6f --- /dev/null +++ b/tests/test-006_interactors/refs/r-interactor-maxBlankCount-normal/stdout @@ -0,0 +1,3 @@ +10 +20 +30 diff --git a/tests/test-006_interactors/run.sh b/tests/test-006_interactors/run.sh index 7d18216..303b914 100644 --- a/tests/test-006_interactors/run.sh +++ b/tests/test-006_interactors/run.sh @@ -18,3 +18,17 @@ java -jar files/crossrun/CrossRun.jar ./interactor-a-plus-b files/"$os"/input.01 tr -d '\r' < output.02 > output.02.nix bash ../scripts/test-ref r-interactor-a-plus-b-2-1 cat output.02.nix rm -f output.02 output.02.nix interactive-a-plus-b interactive-a-plus-b.exe interactor-a-plus-b interactor-a-plus-b.exe interactive_runner.out interactive_runner.err + +# Test maxBlankCount: interactor with normal participant (should pass) +bash ../scripts/compile src/interactor-maxBlankCount.cpp +bash ../scripts/test-ref r-interactor-maxBlankCount-normal "$VALGRIND" ./interactor-maxBlankCount files/"$os"/input.maxBlankCount output.maxBlankCount.normal < files/"$os"/participant.maxBlankCount.normal +tr -d '\r' < output.maxBlankCount.normal > output.maxBlankCount.normal.nix +bash ../scripts/test-ref r-interactor-maxBlankCount-normal-output cat output.maxBlankCount.normal.nix +rm -f output.maxBlankCount.normal output.maxBlankCount.normal.nix + +# Test maxBlankCount: interactor with bad participant (should fail) +bash ../scripts/test-ref r-interactor-maxBlankCount-fail "$VALGRIND" ./interactor-maxBlankCount files/"$os"/input.maxBlankCount output.maxBlankCount.fail < files/"$os"/participant.maxBlankCount.fail +rm -f output.maxBlankCount.fail + +# Cleanup maxBlankCount test files +rm -f interactor-maxBlankCount interactor-maxBlankCount.exe diff --git a/tests/test-006_interactors/src/interactor-maxBlankCount.cpp b/tests/test-006_interactors/src/interactor-maxBlankCount.cpp new file mode 100644 index 0000000..2a43564 --- /dev/null +++ b/tests/test-006_interactors/src/interactor-maxBlankCount.cpp @@ -0,0 +1,30 @@ +#include "testlib.h" +#include + +using namespace std; + +int main(int argc, char *argv[]) { + setName("Interactor maxBlankCount test"); + registerInteraction(argc, argv); + + // Set a low limit for testing (to verify it triggers) + ouf.maxBlankCount = 1000; // ouf is the stream from participant + + // Read the number of queries from input file + int n = inf.readInt(); + + for (int i = 0; i < n; i++) { + // Send query to participant + int query = inf.readInt(); + cout << query << endl; + + // Try to read response from participant + // If participant sent > 1000 spaces, this will cause _pe + int response = ouf.readInt(); + + // Write result + tout << response << endl; + } + + quitf(_ok, "%d queries processed", n); +}