Skip to content

Validate FastSort stdin bounds - #85

Closed
krotname wants to merge 1 commit into
mainfrom
codex/fix-fastsort-stdin-unbounded-allocation-issue
Closed

Validate FastSort stdin bounds#85
krotname wants to merge 1 commit into
mainfrom
codex/fix-fastsort-stdin-unbounded-allocation-issue

Conversation

@krotname

Copy link
Copy Markdown
Owner

Motivation

  • Prevent an availability issue where untrusted stdin could drive unchecked allocations or unbounded token accumulation causing OutOfMemoryError or NegativeArraySizeException in the FastSort CLI.
  • Ensure parsing of numeric and string tokens from stdin is validated and bounded before any heap allocation is performed.

Description

  • Add MAX_PARTICIPANTS and MAX_LOGIN_LENGTH constants and apply them in the CLI run path to limit allocations and token sizes.
  • Replace the unsafe nextInt() with nextInt(String fieldName, int minValue, int maxValue) that enforces digit-only input, overflow checks, and min/max bounds.
  • Replace the unbounded next() with next(int maxLength) and introduce nextNonWhitespace() so tokens are read with a maximum length check and fail early if exceeded.
  • Wire the new bounded parsers into run() so the Participant[] allocation and each login/solved/penalty read are validated while preserving existing sorting behavior for valid inputs.

Testing

  • Ran mvn test which completed successfully (BUILD SUCCESS, 546 tests run) and all unit tests passed.
  • Compiled the changed file with javac -g src/main/java/algorithms/sprint3/FastSort.java which succeeded.
  • Performed manual CLI checks: a normal sample input produced expected output, and malformed/oversized inputs such as 2147483648, 1000000000 and an excessively long login token produced validation IOException and non-zero exit as expected.

Codex Task

@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@krotname

krotname commented Aug 1, 2026

Copy link
Copy Markdown
Owner Author

Superseded by the validated combined merge in #115: #115

@krotname krotname closed this Aug 1, 2026
@krotname
krotname deleted the codex/fix-fastsort-stdin-unbounded-allocation-issue branch August 1, 2026 02:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant