Skip to content

Validate SIDX reference field limits during encoding - #215

Merged
bradh merged 1 commit into
mainfrom
codex/investigate-issue-189
Jul 31, 2026
Merged

Validate SIDX reference field limits during encoding#215
bradh merged 1 commit into
mainfrom
codex/investigate-issue-189

Conversation

@kixelated

Copy link
Copy Markdown
Owner

Summary

  • Reject oversized reference_size, sap_type, and sap_delta_time values before encoding sidx references.
  • Simplify SAP bit packing by using the already validated field values directly.
  • Add coverage for the new TooLarge error path.

Testing

  • Not run (not requested)
  • Merge conflicts and CI failures were not verified in this context

@kixelated
kixelated marked this pull request as ready for review July 17, 2026 22:44
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The extended Sidx body encoder now rejects SegmentReference values that exceed the bit widths of reference_size, sap_type, or sap_delta_time, returning Error::TooLarge(Sidx::KIND). SAP field packing no longer masks validated values before shifting and combining them. A unit test verifies encoding fails for each oversized field.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: validating SIDX reference field limits during encoding.
Description check ✅ Passed The description matches the implemented changes and test coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/investigate-issue-189

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

Comment @coderabbitai help to get the list of available commands.

@bradh

bradh commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

@CodeRabbit review

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
src/sidx.rs (1)

117-122: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use branchless bitwise logic to simplify packing.

You can eliminate the match expression to avoid potential clippy::match_bool violations. As per coding guidelines, code must be clippy-clean. Casting the boolean to a u32 and shifting it directly makes the packing branchless, mathematically equivalent, and more concise.

♻️ Proposed refactor
-            let sap_flag_and_type_and_delta_time = match reference.starts_with_sap {
-                true => {
-                    0x8000_0000 | ((reference.sap_type as u32) << 28) | reference.sap_delta_time
-                }
-                false => ((reference.sap_type as u32) << 28) | reference.sap_delta_time,
-            };
+            let sap_flag_and_type_and_delta_time = ((reference.starts_with_sap as u32) << 31)
+                | ((reference.sap_type as u32) << 28)
+                | reference.sap_delta_time;

(Note: You can apply the same branchless simplification to reference_type_and_size on lines 111-114.)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/sidx.rs` around lines 117 - 122, Replace the boolean match used to
compute sap_flag_and_type_and_delta_time with branchless bitwise packing by
casting reference.starts_with_sap to u32 and shifting it into the high flag bit,
preserving the existing sap_type and sap_delta_time fields. Apply the same
match_bool refactor to reference_type_and_size, using its corresponding boolean
flag and bit layout.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/sidx.rs`:
- Around line 117-122: Replace the boolean match used to compute
sap_flag_and_type_and_delta_time with branchless bitwise packing by casting
reference.starts_with_sap to u32 and shifting it into the high flag bit,
preserving the existing sap_type and sap_delta_time fields. Apply the same
match_bool refactor to reference_type_and_size, using its corresponding boolean
flag and bit layout.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 44ae5032-bf10-44fb-82f4-bf1c2898f1e1

📥 Commits

Reviewing files that changed from the base of the PR and between ac798db and 010e69b.

📒 Files selected for processing (1)
  • src/sidx.rs

@bradh
bradh merged commit a14bfde into main Jul 31, 2026
1 check passed
@bradh
bradh deleted the codex/investigate-issue-189 branch July 31, 2026 09:40
@github-actions github-actions Bot mentioned this pull request Jul 28, 2026
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