Skip to content

Add boundary checks in gen_associated_data_from_range()#847

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/add-boundary-checks-gen-associated-data
Draft

Add boundary checks in gen_associated_data_from_range()#847
Copilot wants to merge 2 commits intomainfrom
copilot/add-boundary-checks-gen-associated-data

Conversation

Copy link
Contributor

Copilot AI commented Mar 17, 2026

gen_associated_data_from_range() performed unchecked u32 arithmetic on user-supplied CLI values: end - start underflows when end < start, and end - start + 1 overflows when end == u32::MAX && start == 0.

Changes

  • Input validation: Return CMDToolError early when end < start
  • Checked arithmetic: Replace end - start + 1 with (end - start).checked_add(1), returning an error on overflow
  • Tests: Add test_gen_associated_data_from_range_end_less_than_start and test_gen_associated_data_from_range_max_overflow
// Before (panics/wraps on bad input)
let num_ints = end - start + 1;

// After
if end < start {
    return Err(CMDToolError {
        details: format!("invalid range: end ({end}) must be greater than or equal to start ({start})"),
    });
}
let num_ints = (end - start).checked_add(1).ok_or_else(|| CMDToolError {
    details: format!("range [{start}, {end}] is too large: count overflows u32"),
})?;
Original prompt

This section details on the original issue you should resolve

<issue_title>Add boundary checks in gen_associated_data_from_range()</issue_title>
<issue_description>> Since start/end are user-provided (via the CLI wrapper), this function should defensively validate end >= start and avoid unchecked u32 arithmetic (currently end - start + 1 will overflow/panic when end < start, and can also overflow when end == u32::MAX && start == 0). Consider returning an error on invalid ranges and computing the count with checked arithmetic.

Originally posted by @copilot in #763</issue_description>

Comments on the Issue (you are @copilot in this section)


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Co-authored-by: harsha-simhadri <5590673+harsha-simhadri@users.noreply.github.com>
Copilot AI changed the title [WIP] Add boundary checks in gen_associated_data_from_range() Add boundary checks in gen_associated_data_from_range() Mar 17, 2026
Copilot AI requested a review from harsha-simhadri March 17, 2026 20:28
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.

Add boundary checks in gen_associated_data_from_range()

2 participants