Verify depth metrics roi size - #14133
Conversation
There was a problem hiding this comment.
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
| 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. |
There was a problem hiding this comment.
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 ).
| 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. |
| 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. |
There was a problem hiding this comment.
Grammatical error in comment: 'Resolution have changed' should be 'Resolution has changed'.
| 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. |
Tracked on [LRS-1290]