Conversation
…ions Fail closed on untrusted GGUF headers before allocation or loops proportional to declared counts. Typed LimitExceeded and HostSizeOverflow errors name the budget or field. Default and mmap readers share the same policy; trusted callers can override without changing defaults. Linear: RM-1358 Co-authored-by: Raul Cardenas Montoya <montoyaraul34@gmail.com>
|
Warning Review limit reachedNext included review available in 52 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (12)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🤖 CodeAnt AI — Review Status
|
Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
This is a comprehensive security enhancement that properly addresses resource exhaustion and integer overflow risks when parsing untrusted GGUF files. The implementation follows security best practices with fail-closed design, checked arithmetic throughout, and excellent test coverage. No blocking issues found.
Key strengths:
- Proper use of
checked_add/checked_multo prevent integer overflows - Type-safe conversions with
try_frominstead of lossy casts - Limits checked before allocation/iteration
- Comprehensive error types with specific field names
- Thorough test coverage including boundary conditions
The code is production-ready and properly implements defense-in-depth for untrusted input handling.
You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.
| tensor.absolute_offset = tensor_data_offset | ||
| .checked_add(tensor.relative_offset) | ||
| .ok_or_else(|| { | ||
| invalid_layout( | ||
| path, | ||
| format!("tensor '{}' absolute offset overflow", tensor.name), | ||
| ) | ||
| })?; |
There was a problem hiding this comment.
Suggestion: A relative offset of zero places the tensor at tensor_data_offset, but smaller or overlapping offsets are not rejected, so tensor reads can expose metadata or another tensor's bytes. [logic error]
Assessment: 🟠 Major · 🔁 Occurrence: Rarely
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** src/gguf/layout.rs
**Line:** 435:442
**Comment:**
*Logic Error: A relative offset of zero places the tensor at `tensor_data_offset`, but smaller or overlapping offsets are not rejected, so tensor reads can expose metadata or another tensor's bytes.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
User description
Fixes RM-1358.
GGUF files are untrusted. This adds one documented
ParseLimitspolicy and fail-closed host-size conversions so crafted headers cannot request unbounded allocation or iteration.What changed
ParseLimitswith generous defaults covering KV count, tensor count, string bytes, array work items, tensor rank, and metadata bytes.ParserError::LimitExceeded(names the budget) andParserError::HostSizeOverflow(names the field).u64sizes convert withtry_frominstead of lossyas usize.load_gguf_with_limits/parse_bytes_with_limits/load_gguf_mmap_with_limitslet trusted callers override without changing default safety.parse_layoutand therefore the same budgets.Tests
Required cases in
tests/gguf_limits.rsplus cursor/limits unit tests:u64::MAXstring/count/offset/array fieldsu32::MAX) and element-count multiplication overflowLocal CI evidence
All three passed on this branch (84 lib tests + 16 limits tests + existing smoke/mmap/safetensors + doctests).
Linear Issue: RM-1358
Summary by cubic
Adds resource budgets and checked host-size conversions to GGUF parsing so crafted headers cannot request unbounded allocation or iteration. New
ParseLimitswith generous defaults, typed errors for limit and size overflow, and*_with_limitsentry points for trusted callers. Addresses RM-1358.Details
ParseLimitscovering KV count, tensor count, string bytes, array work, tensor rank, and metadata bytes.u64sizes now convert withtry_frominstead of lossyas usize.load_gguf_with_limits,parse_bytes_with_limits,load_gguf_mmap_with_limitsfor trusted overrides.Written for commit 4578766. Summary will update on new commits.
CodeAnt-AI Description
Protect GGUF parsing from untrusted resource requests and arithmetic overflow
What Changed
Impact
✅ Prevented unbounded allocation from crafted GGUF headers✅ Fewer parser crashes and wraparound layout errors✅ Clearer resource-limit and size-overflow errors💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.