Skip to content

Verify depth metrics roi size - #14133

Merged
Nir-Az merged 2 commits into
realsenseai:developmentfrom
OhadMeir:development
Jul 20, 2025
Merged

Verify depth metrics roi size#14133
Nir-Az merged 2 commits into
realsenseai:developmentfrom
OhadMeir:development

Conversation

@OhadMeir

Copy link
Copy Markdown
Contributor

Tracked on [LRS-1290]

@OhadMeir
OhadMeir requested a review from Nir-Az July 15, 2025 12:03
@Nir-Az
Nir-Az requested a review from Copilot July 15, 2025 20:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 validation to prevent accessing pixels outside the current frame resolution when calculating depth metrics. The change ensures that if the resolution has changed since the ROI (Region of Interest) was calculated, the function returns early to avoid illegal memory access.

  • Adds bounds checking to compare frame dimensions against ROI boundaries
  • Removes unnecessary mutex and lock guard that were protecting vector operations

Comment thread tools/depth-quality/depth-metrics.h Outdated
snapshot_metrics result{ w, h, roi, {} };

std::mutex m;
if( w < roi.max_x || h < roi.max_y ) // Resolution have changed since calculating roi, avoid accessing illegal pixels.

Copilot AI Jul 15, 2025

Copy link

Choose a reason for hiding this comment

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

The bounds check logic is incorrect. It should use <= instead of < because pixel coordinates are typically 0-indexed, so valid x coordinates range from 0 to w-1, and valid y coordinates from 0 to h-1. The condition should be if( w <= roi.max_x || h <= roi.max_y ).

Suggested change
if( w < roi.max_x || h < roi.max_y ) // Resolution have changed since calculating roi, avoid accessing illegal pixels.
if( w <= roi.max_x || h <= roi.max_y ) // Resolution has changed since calculating roi, avoid accessing illegal pixels.

Copilot uses AI. Check for mistakes.
Comment thread tools/depth-quality/depth-metrics.h Outdated
snapshot_metrics result{ w, h, roi, {} };

std::mutex m;
if( w < roi.max_x || h < roi.max_y ) // Resolution have changed since calculating roi, avoid accessing illegal pixels.

Copilot AI Jul 15, 2025

Copy link

Choose a reason for hiding this comment

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

Grammatical error in comment: 'Resolution have changed' should be 'Resolution has changed'.

Suggested change
if( w < roi.max_x || h < roi.max_y ) // Resolution have changed since calculating roi, avoid accessing illegal pixels.
if( w < roi.max_x || h < roi.max_y ) // Resolution has changed since calculating roi, avoid accessing illegal pixels.

Copilot uses AI. Check for mistakes.
@Nir-Az
Nir-Az merged commit e82e44e into realsenseai:development Jul 20, 2025
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.

3 participants