Repository navigation
fix(gguf): reject tensor offsets not aligned to general.alignment (#120) - #121
Conversation
…-2204, #120) finalize_tensor_offsets checked offset/size overflow, past-EOF and overlap, but not that each tensor's relative_offset is a multiple of general.alignment, which the GGUF spec and llama.cpp require. Return InvalidLayout naming the tensor, its offset and the alignment. The check runs after the offset-overflow guard and before the bounds/overlap checks. Tests cover a misaligned offset at the default alignment 32, at a declared alignment 64, and offsets that are aligned at 64 (or 16) but misaligned at another alignment. The overlap fixture used unaligned offset 4 and now uses aligned offsets so it still exercises overlap. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XFfzKmA7iVUdRhsaNkdQLs
🤖 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 · |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
There was a problem hiding this comment.
Review Summary
This PR correctly implements GGUF tensor offset alignment validation per the spec and llama.cpp behavior. The core change in finalize_tensor_offsets is well-placed in the check ordering chain (after the checked_add overflow guard, before bounds/overlap checks), and the logic !tensor.relative_offset.is_multiple_of(alignment) is correct — 0 passes as a valid multiple of any alignment, and the parser enforces alignment > 0 && alignment.is_power_of_two() earlier in read_metadata_section.
The test coverage is thorough: rejection at default alignment (16, 33), rejection when declared alignment overrides default (offset 32 @ alignment 64), acceptance at a correctly aligned offset (192 @ alignment 64, rejected @ 128), and acceptance of general.alignment 16 allowing offset 16. The overlapping_payloads_fail_closed fixture update correctly migrates from the formerly-misaligned offset 4 to aligned offsets, preserving the overlap-specific failure mode.
No blocking defects were identified. The changes are safe to merge.
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.
CodeAnt PR Risk: Low Risk
Assessed commit: |
User description
What changed
finalize_tensor_offsets(src/gguf/layout.rs) now returns the existingInvalidLayouterror when a tensor'srelative_offsetis not a multiple ofgeneral.alignment(default 32). The message names the tensor, its offset and the alignment, e.g.tensor 'x' has relative_offset 16, which is not a multiple of general.alignment 32. This matches the GGUF spec and llama.cpp, which engram-parser previously accepted. It is spec strictness, not memory safety.Check ordering: it runs after the
checked_addabsolute-offset overflow guard (sou64::MAXstill reports overflow) and before the past-EOF and overlap checks.Tests (
tests/gguf_directory_invariants.rs)general.alignmentof 64 is rejected (aligned at 32, not 64).One existing test changed:
overlapping_payloads_fail_closedused relative offset 4, which is now rejected as misaligned before overlap is reached. It now uses aligned offsets (a 64-byte tensor at 0 and an 8-byte tensor at 32) so it still tests overlap. No checked-in fixture undertests/fixtureswas affected.Verification
cargo test --quiet: 139 passed, 0 failed, 2 ignoredcargo test --all-features --quiet: 245 passed, 0 failed, 3 ignoredcargo clippy --all-targets --all-features -- -D warnings: cleancargo fmt --check: cleanCHANGELOG: added an
[Unreleased]section (none existed).Closes #120
Linear: RM-2204
Generated by Claude Code
Summary by cubic
Rejects GGUF tensor offsets that aren't a multiple of
general.alignment(default 32), matching the GGUF spec and llama.cpp. Files that previously parsed now fail with anInvalidLayoutnaming the tensor, offset, and alignment.Bug Fixes
overlapping_payloads_fail_closeduses aligned offsets so it still exercises overlap.Written for commit d9c5c7f. Summary will update on new commits.
CodeAnt-AI Description
Reject GGUF files with misaligned tensor offsets
What Changed
Impact
✅ Misaligned GGUF files rejected during parsing✅ Declared tensor alignment enforced✅ Clearer errors identify the offending tensor and offset💡 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.
Summary by CodeRabbit