Skip to content

Harden sprint4 CLI solvers against input-driven DoS and unbounded allocation - #84

Closed
krotname wants to merge 1 commit into
mainfrom
codex/propose-fix-for-input-driven-dos-vulnerability
Closed

Harden sprint4 CLI solvers against input-driven DoS and unbounded allocation#84
krotname wants to merge 1 commit into
mainfrom
codex/propose-fix-for-input-driven-dos-vulnerability

Conversation

@krotname

Copy link
Copy Markdown
Owner

Motivation

  • Prevent denial-of-service from attacker-controlled stdin sizes and predictable hash collisions in the sprint4 CLIs by adding bounds and unpredictability.
  • Avoid unbounded memory or CPU growth when these utilities are invoked on untrusted input.

Description

  • For Map: add a per-process random HASH_SEED and mix keys before bucket selection to mitigate attacker-controlled collision chains, add MAX_COMMANDS, replace accumulated StringBuilder output with streamed BufferedWriter, add bounded and validated integer parsing (nextInt(min,max)), validate commands, and move CLI logic into solve() wrapped by a safe main that rejects invalid/excessive input.
  • For FindSystem: introduce MAX_DOCUMENTS, MAX_QUERIES, and MAX_LINE_LENGTH, enforce these limits in nextInt(max) and nextLine(maxLength), stream per-query output with BufferedWriter, and catch IOException in main so oversized or malformed input is rejected without exhausting resources.
  • Keep original algorithms and data structures (chained hash table and inverted-index logic) but add defensive input handling and a randomized hash mapping to preserve functionality while reducing attack surface.

Testing

  • Compiled both classes with javac -d /tmp/cwjclasses src/main/java/algorithms/sprint4/Map.java src/main/java/algorithms/sprint4/FindSystem.java and compilation succeeded.
  • Exercised CLIs with representative inputs for algorithms.sprint4.Map and algorithms.sprint4.FindSystem and observed expected outputs.
  • Verified oversized/malformed inputs are rejected (e.g. very large n now triggers a controlled IOException rather than exhausting heap).
  • Ran the full test suite with mvn test which completed successfully (546 tests run, 0 failures/errors).

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: d47ca83d2e

ℹ️ 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/sprint4/FindSystem.java
@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/propose-fix-for-input-driven-dos-vulnerability 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