Skip to content

Conversation

@geoffw0
Copy link
Contributor

@geoffw0 geoffw0 commented Jan 12, 2026

Add a barrier for <alloc::vec::Vec>::split_off in rust/uncontrolled-allocation-size. This method is recognised as a (generated) sink, however in practice the size of any allocation made by split_off is bounded by the size of the original vector - so it's never an "uncontrolled" allocation.

Update: I've created an issue for adding support for Rust barriers being defined in models-as-data, and convert this barrier to MaD. This isn't particularly high priority right now but if we end up with a lot of barriers the importance could increase.

Copilot AI review requested due to automatic review settings January 12, 2026 13:59
@geoffw0 geoffw0 requested a review from a team as a code owner January 12, 2026 13:59
@geoffw0 geoffw0 added no-change-note-required This PR does not need a change note Rust Pull requests that update Rust code labels Jan 12, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a barrier to the rust/uncontrolled-allocation-size query to prevent false positives for Vec::split_off and String::split_off methods. These methods are recognized as allocation sinks by the query's generated models, but in practice any allocation they perform is bounded by the size of the original collection, making them safe from uncontrolled allocation vulnerabilities.

Changes:

  • Added a ModelledBarrier class that blocks data flow to the index argument of split_off methods on Vec and String
  • Added test case demonstrating that Vec::split_off is correctly identified as safe
  • Updated expected test results to reflect line number changes from the new test case

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
rust/ql/lib/codeql/rust/security/UncontrolledAllocationSizeExtensions.qll Implements a new barrier for split_off methods on Vec and String types
rust/ql/test/query-tests/security/CWE-770/main.rs Adds test case for Vec::split_off with uncontrolled size parameter
rust/ql/test/query-tests/security/CWE-770/UncontrolledAllocationSize.expected Updates expected results with adjusted line numbers from new test code

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +241 to +242
let mut v2 = vec![1, 2, 3, 4, 5, 6];
let _ = v2.split_off(v); // GOOD (any allocation is bounded by the initial size of the vector)
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The barrier implementation in UncontrolledAllocationSizeExtensions.qll includes both Vec::split_off and String::split_off, but only Vec::split_off is tested here. Consider adding a test case for String::split_off as well to ensure both barriers work correctly.

Copilot uses AI. Check for mistakes.
/**
* A barrier for uncontrolled allocation size flow into particular functions.
*/
private class ModelledBarrier extends Barrier {

Check warning

Code scanning / CodeQL

Misspelling Warning

This class name contains the non-US spelling 'modelled', which should instead be 'modeled'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-change-note-required This PR does not need a change note Rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant