Skip to content

Validate SleightOfHand input - #88

Closed
krotname wants to merge 1 commit into
mainfrom
codex/fix-unvalidated-grid-input-in-sleightofhand
Closed

Validate SleightOfHand input#88
krotname wants to merge 1 commit into
mainfrom
codex/fix-unvalidated-grid-input-in-sleightofhand

Conversation

@krotname

Copy link
Copy Markdown
Owner

Motivation

  • Prevent crashes and denial-of-service from untrusted stdin by bounding token reads and validating grid cell values before using them as array indexes.

Description

  • Add a bounded token reader next(int maxLength) and switch board reads to in.next(4) so oversized row tokens are rejected before unbounded buffer growth can exhaust memory.
  • Validate each CLI grid character and throw an IOException for any non-. and non-digit character before indexing count[ch - '0'].
  • Wrap main invocation in a try/catch to report IOException and IllegalArgumentException messages instead of letting uncaught exceptions crash the process.
  • Validate caller-supplied matrix values in solve(int, int[][]) and throw IllegalArgumentException for values outside 0..9 before indexing the digit count array.

Testing

  • mvn test -q was attempted but failed due to Maven Central returning 503 Service Unavailable while resolving the JUnit BOM.
  • Compiled the class with javac and ran a valid sample input which produced the expected output 2 (succeeded).
  • Ran a malformed grid containing ! and observed a handled IOException with message Invalid grid cell: ! (succeeded).
  • Ran a very large token under -Xmx16m and observed IOException: Token length exceeds 4, preventing heap exhaustion (succeeded).
  • Executed a small harness calling solve(1, new int[][]{{10,0,0,0}}) and observed IllegalArgumentException: Grid values must be between 0 and 9 (succeeded).

Codex Task

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d1e321ac30

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/main/java/algorithms/sprint1/SleightOfHand.java
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
52.4% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 23.07692% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...rc/main/java/algorithms/sprint1/SleightOfHand.java 23.07% 8 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@krotname

krotname commented Aug 1, 2026

Copy link
Copy Markdown
Owner Author

Закрываю как superseded by #116: изменения перенесены в одну проверенную ветку, все review findings учтены; локальный mvn verify прошёл полностью.

@krotname krotname closed this Aug 1, 2026
@krotname
krotname deleted the codex/fix-unvalidated-grid-input-in-sleightofhand branch August 1, 2026 08:36
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