Skip to content

Avoid panic on truncated input by using bounds-checked slice in CLI#688

Merged
ChristopherRabotin merged 2 commits intonyx-space:masterfrom
jmestwa-coder:cli-file-record-bounds-check
Apr 24, 2026
Merged

Avoid panic on truncated input by using bounds-checked slice in CLI#688
ChristopherRabotin merged 2 commits intonyx-space:masterfrom
jmestwa-coder:cli-file-record-bounds-check

Conversation

@jmestwa-coder
Copy link
Copy Markdown
Contributor

Summary

This PR improves the robustness of the CLI by removing panic paths when handling user-provided input files.


Architectural Changes

None.


New Features

None.


Improvements

  • Replaced unchecked slicing (&bytes[..SIZE]) with bounds-checked access using .get(..SIZE)
  • Ensures safe handling of truncated or malformed input files
  • Aligns with existing safe slice usage patterns in the codebase
  • Replaced one .unwrap() in convert_fk flow with proper error propagation using .context(...)

Bug Fixes

  • Fixed panic when processing files smaller than FileRecord::SIZE
  • Fixed potential panic in convert_fk path by replacing .unwrap() with error propagation

Testing and Validation

  • Verified that truncated files now return a clean error instead of panicking
  • Confirmed valid files behave unchanged
  • Ensured compilation succeeds without introducing new warnings or errors

Documentation

No documentation changes.


Notes

  • Changes are limited to CLI only
  • No impact on library behavior
  • No API changes
  • Follows existing error handling patterns

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request improves error handling in anise-cli/src/main.rs by replacing direct slice indexing with safe access and converting some .unwrap() calls to proper error propagation. The review feedback correctly identifies remaining .unwrap() calls that should be replaced with the ? operator to ensure the application handles malformed input gracefully without panicking.

Comment thread anise-cli/src/main.rs Outdated
Comment thread anise-cli/src/main.rs Outdated
@ChristopherRabotin
Copy link
Copy Markdown
Member

Could you apply the attached patch. I can't push to your branch. Thanks

patch.txt

@jmestwa-coder jmestwa-coder force-pushed the cli-file-record-bounds-check branch from 647ec5e to 8531332 Compare April 24, 2026 11:37
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@jmestwa-coder jmestwa-coder force-pushed the cli-file-record-bounds-check branch from 8531332 to 4cdd039 Compare April 24, 2026 11:48
@jmestwa-coder
Copy link
Copy Markdown
Contributor Author

I’ve applied the changes to the branch.

Please let me know if anything else needs adjustment.

@ChristopherRabotin
Copy link
Copy Markdown
Member

Great, thank you!

@ChristopherRabotin ChristopherRabotin merged commit b605e56 into nyx-space:master Apr 24, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants