Skip to content

Conversation

@smowton
Copy link
Contributor

@smowton smowton commented Sep 12, 2025

Drive-by fix noticed while looking through alleged bad autofixes (autofix used a < test and CodeQL claimed it was an invalid fix)

@smowton smowton requested a review from a team as a code owner September 12, 2025 10:47
Copilot AI review requested due to automatic review settings September 12, 2025 10:47
@github-actions github-actions bot added the JS label Sep 12, 2025
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 enhances the JavaScript off-by-one array access detection by recognizing that a less-than test (<) provides the same protection as a not-equal test (!=) when mitigating off-by-one errors in array bounds checking.

  • Added a new getLengthLTGuard function to detect index < array.length conditions
  • Updated the main query logic to exclude cases where either a not-equal or less-than guard exists
  • Added test case demonstrating the fix with i < a.length guard

Reviewed Changes

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

File Description
javascript/ql/src/LanguageFeatures/LengthComparisonOffByOne.ql Added getLengthLTGuard function and updated query to consider less-than guards
javascript/ql/test/query-tests/LanguageFeatures/LengthComparisonOffByOne/tst.js Added test case for function with less-than guard to verify the fix

@smowton smowton force-pushed the smowton/fix/length-comparison-off-by-one-fp branch from 8c5afd2 to db5c581 Compare September 12, 2025 13:32
@smowton smowton merged commit c375f24 into github:main Sep 15, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants