TTPF: reject backwards chunk ranges and excessive padding #14

Open
github-bot wants to merge 1 commit from github-bot/gh-14 into master AGit
Owner

@⁠yefan911 on GitHub · 2026-11-26 18:21 UTC · original
yefan911:fix/ttpf-chunk-ranges → master · +84 −3 · 1 files · 1 commits · open

Store::from_bytes currently clamps backwards physical and virtual chunk ranges to zero with saturating_sub. It also accepts padding larger than the chunk, which data_len then hides with another saturating subtraction. Malformed chunk tables consequently look like valid empty chunks; backwards virtual offsets also violate the ordering expected by locate.

Reject these inconsistent ranges with InvalidData errors identifying the chunk. Keep valid zero-length ranges and fully padded chunks accepted. Physical EOF checks remain in chunk_bytes, preserving the existing synthetic high-offset metadata test and its lazy bounds validation.

Validation on Windows x86-64 / Rust 1.99.1:

  • Seven new in-memory synthetic store tests cover ordered ranges, backwards physical and virtual offsets, excessive and exact-length padding, empty chunks, and deferred EOF checks. The three new malformed-range cases fail on the original parser and pass with the fix.
  • cargo test --locked: 34 unit/integration tests and one doctest passed.
  • cargo clippy --all-targets --all-features --locked -- -D warnings: passed.
  • git diff --check: passed. Full cargo fmt -- --check reports existing formatting differences; comparing formatter corrections for ttpf.rs before and after this patch shows the same three pre-existing changes and no new formatting differences. No unrelated formatting edits included.

No game files or retail checks used. New fixtures contain only generated headers and zero-filled synthetic bytes. No dependencies or generated tables changed.

AI-assisted: GPT-6.1 Sol.

Summary by CodeRabbit

  • Bug Fixes
    • Invalid chunk ranges that run backwards or exceed the stored chunk length are now rejected instead of being accepted as empty ranges.
    • Reading chunks with out-of-bounds file ranges now reports an error.
**@⁠yefan911** on GitHub · 2026-11-26 18:21 UTC · [original](https://github.com/Ahmet-Dedeler/bcpack-rs/pull/14) `yefan911:fix/ttpf-chunk-ranges` → `master` · +84 −3 · 1 files · 1 commits · open `Store::from_bytes` currently clamps backwards physical and virtual chunk ranges to zero with `saturating_sub`. It also accepts padding larger than the chunk, which `data_len` then hides with another saturating subtraction. Malformed chunk tables consequently look like valid empty chunks; backwards virtual offsets also violate the ordering expected by `locate`. Reject these inconsistent ranges with `InvalidData` errors identifying the chunk. Keep valid zero-length ranges and fully padded chunks accepted. Physical EOF checks remain in `chunk_bytes`, preserving the existing synthetic high-offset metadata test and its lazy bounds validation. Validation on Windows x86-64 / Rust 1.99.1: - Seven new in-memory synthetic store tests cover ordered ranges, backwards physical and virtual offsets, excessive and exact-length padding, empty chunks, and deferred EOF checks. The three new malformed-range cases fail on the original parser and pass with the fix. - `cargo test --locked`: 34 unit/integration tests and one doctest passed. - `cargo clippy --all-targets --all-features --locked -- -D warnings`: passed. - `git diff --check`: passed. Full `cargo fmt -- --check` reports existing formatting differences; comparing formatter corrections for `ttpf.rs` before and after this patch shows the same three pre-existing changes and no new formatting differences. No unrelated formatting edits included. No game files or retail checks used. New fixtures contain only generated headers and zero-filled synthetic bytes. No dependencies or generated tables changed. AI-assisted: GPT-6.1 Sol. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Invalid chunk ranges that run backwards or exceed the stored chunk length are now rejected instead of being accepted as empty ranges. * Reading chunks with out-of-bounds file ranges now reports an error. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 18:56:16 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-26 18:21 UTC · original · edited 2026-11-26 18:23 UTC

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Store::from_bytes now rejects backwards file or virtual ranges and padding larger than a chunk’s stored length. Tests cover valid and invalid ranges, empty and fully padded chunks, and reads beyond file bounds.

Changes

Chunk range validation

Layer / File(s) Summary
Chunk range checks
src/ttpf.rs
Store::from_bytes uses checked subtraction for file and virtual ranges and rejects padding larger than the stored range. Tests cover ordered, backwards, empty, fully padded, and out-of-file chunks.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: ahmet-dedeler

Merge Risk: Minimal · up to 7b30d

This change makes the parser reject malformed chunk ranges and excessive padding instead of treating them as empty chunks. Valid zero-length and fully padded chunks are still accepted. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the two main changes: rejecting backwards chunk ranges and rejecting excessive padding in the TTPF parser. The raw summary confirms that Store::from_bytes now rejects backwards file or…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the two main changes: rejecting backwards chunk ranges and rejecting excessive padding in the TTPF parser. The raw summary confirms that Store::from_bytes now rejects backwards file or virtual ranges and padding larger than the chunk length, so the title matches the changeset. It is specific and concise, and it uses the TTPF scope prefix that the objectives also use.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9b8a9910-18d7-48a7-98f1-44dd43d00eb7
Commits

Reviewing files that changed from the base of the PR and between 7b2b42122c and 7b30d01735.

Files selected for processing: 1

  • src/ttpf.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-11-26 18:21 UTC · [original](https://github.com/Ahmet-Dedeler/bcpack-rs/pull/14#issuecomment-7200362606) · edited 2026-11-26 18:23 UTC <!-- coderabbit-ai-generated:v1 --> <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/Ahmet-Dedeler/bcpack-rs/pull/14?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg" alt="Explain Change →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- recent_review_status_start --> No actionable comments were generated in the recent review. <!-- recent_review_status_end --> <!-- walkthrough_start --> ### Walkthrough `Store::from_bytes` now rejects backwards file or virtual ranges and padding larger than a chunk’s stored length. Tests cover valid and invalid ranges, empty and fully padded chunks, and reads beyond file bounds. ### Changes **Chunk range validation** |Layer / File(s)|Summary| |:---|:---| |**Chunk range checks** <br> `src/ttpf.rs`|`Store::from_bytes` uses checked subtraction for file and virtual ranges and rejects padding larger than the stored range. Tests cover ordered, backwards, empty, fully padded, and out-of-file chunks.| <!-- change_assessment_start --> **Estimated code review effort:** 2 (Simple) | ~10 minutes <!-- change_assessment_commit:"7b30d017350f3dc76ce9492b230636daa3fc4134" --> <!-- change_assessment_priority:{"version":1,"urgency":"p2","manual":false} --> Change: Bug fix <!-- change_assessment_end --> Suggested reviewers: `ahmet-dedeler` <!-- walkthrough_end --> <details> <summary><strong>Merge Risk:</strong> <strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/risk-unassessed-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minimal</strong> · up to <code>7b30d</code></summary> <dl> <dd> <br> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `7b30d` --> <!-- final_review_risk_coverage:{"sourceCommitId":"7b30d017350f3dc76ce9492b230636daa3fc4134","coveredCommitId":"7b30d017350f3dc76ce9492b230636daa3fc4134","kind":"reviewed"} --> This change makes the parser reject malformed chunk ranges and excessive padding instead of treating them as empty chunks. Valid zero-length and fully padded chunks are still accepted. No merge-blocking risk was found. <!-- final_review_risk_end --> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_start --> <details> <summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 4</strong></summary> <dl> <dd> <br> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Description Check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped - CodeRabbit’s high-level summary is enabled. | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title names the two main changes: rejecting backwards chunk ranges and rejecting excessive padding in the TTPF parser. The raw summary confirms that Store::from_bytes now rejects backwards file or… | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | <details> <summary><strong>Full details: Title check</strong></summary> <dl> <dd> <br> **Explanation** The title names the two main changes: rejecting backwards chunk ranges and rejecting excessive padding in the TTPF parser. The raw summary confirms that Store::from_bytes now rejects backwards file or virtual ranges and padding larger than the chunk length, so the title matches the changeset. It is specific and concise, and it uses the TTPF scope prefix that the objectives also use. </dd> </dl> </details> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- finishing_touch_checkbox_start --> <details> <summary><strong>Finishing Touches</strong></summary> <dl> <dd> <br> <details open> <summary><strong>Generate unit tests (beta)</strong></summary> <dl> <dd> <br> - [ ] <!-- {"checkboxId": "f47ac10b-58cc-4372-a567-0e02b2c3d479", "radioGroupId": "utg-output-choice-group-unknown_comment_id"} --> Create a new PR </dd> </dl> </details> </dd> </dl> </details> <!-- finishing_touch_checkbox_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autofix</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=Ahmet-Dedeler/bcpack-rs&utm_content=14)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary><strong>Share</strong></summary> <dl> <dd> <br> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </dd> </dl> </details> <!-- tips_end --> <!-- recent_review_start --> <h6> <details> <summary><strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="12" height="12" align="absmiddle" alt=""></picture> Recent review info</strong></summary> <dl> <dd> <br> <!-- review_info_content --> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</strong></summary> <dl> <dd> <br> - **Source mode**: Auto - **Repository**: Unavailable - **Branch**: Unavailable - **File**: No configuration file from this repository applied - **Commit**: Unavailable - **Layers**: Organization UI - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `9b8a9910-18d7-48a7-98f1-44dd43d00eb7` </dd> </dl> </details> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal.svg" width="16" height="16" align="absmiddle" alt=""></picture> Commits</strong></summary> <dl> <dd> <br> Reviewing files that changed from the base of the PR and between 7b2b42122c6b05787506f212e9a2570999d3f143 and 7b30d017350f3dc76ce9492b230636daa3fc4134. </dd> </dl> </details> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 1</strong></summary> <dl> <dd> <br> * `src/ttpf.rs` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review. </dd> </dl> </details> </h6> <!-- recent_review_end -->
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/14/head:github-bot/gh-14'
git switch 'github-bot/gh-14'

Merge

Merge the changes and update on Forgejo.
git switch 'master'
git merge --no-ff 'github-bot/gh-14'
git switch 'github-bot/gh-14'
git rebase 'master'
git switch 'master'
git merge --ff-only 'github-bot/gh-14'
git switch 'github-bot/gh-14'
git rebase 'master'
git switch 'master'
git merge --no-ff 'github-bot/gh-14'
git switch 'master'
git merge --squash 'github-bot/gh-14'
git switch 'master'
git merge --ff-only 'github-bot/gh-14'
git switch 'master'
git merge 'github-bot/gh-14'
git push origin 'master'
This discussion has been locked. Commenting is limited to contributors.
No description provided.