Skip to content

Fix WarpPerspective::GetFillValue. #5575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 22, 2024

Conversation

mzient
Copy link
Contributor

@mzient mzient commented Jul 22, 2024

Category:

Bug fix (non-breaking change which fixes an issue)
Refactoring (Redesign of existing code that doesn't affect functionality)

Description:

Fix copying FillValue - use actual number of elements in the vector.
Check that the number of channels doesn't exceed 4 (CV-CUDA limit).
Minor style fixes and improved structure packing.

Additional information:

Affected modules and functionalities:

Key points relevant for the review:

Tests:

  • Existing tests apply
  • New tests added
    • Python tests
    • GTests
    • Benchmark
    • Other
  • N/A

Checklist

Documentation

  • Existing documentation applies
  • Documentation updated
    • Docstring
    • Doxygen
    • RST
    • Jupyter
    • Other
  • N/A

DALI team only

Requirements

  • Implements new requirements
  • Affects existing requirements
  • N/A

REQ IDs: N/A

JIRA TASK: DALI-4041

Add more error checks.
Minor style fixes and improved structure packing.

Signed-off-by: Michal Zientkiewicz <[email protected]>
std::vector<float> fill_value_arg_{0, 0, 0, 0};
float4 fill_value_{0, 0, 0, 0};
float4 fill_value_;
bool inverse_map_ = false;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Putting small fields next to one another improves structure packing.

Comment on lines +165 to +166
if (channels > 4)
DALI_FAIL("Images with more than 4 channels are not supported.");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We use float4 for fill_value.

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [16804669]: BUILD STARTED

@@ -108,16 +108,16 @@ class WarpPerspective : public nvcvop::NVCVSequenceOperator<StatelessOperator> {
float4 GetFillValue(int channels) const {
if (fill_value_arg_.size() > 1) {
if (channels > 0) {
if (channels == static_cast<int>(fill_value_arg_.size())) {
float4 fill_value{0, 0, 0, 0};
memcpy(&fill_value, fill_value_arg_.data(), sizeof(decltype(fill_value)));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The bug is in this line - fill_value_arg_ is constructed with exact length in line 95, overriding the default constructor from 233, which is never used. This leads to invalid read of size 16, which is up to 12 bytes beyond the vector end.

@mzient mzient assigned jantonguirao and unassigned awolant Jul 22, 2024
@dali-automaton
Copy link
Collaborator

CI MESSAGE: [16804669]: BUILD PASSED

@mzient mzient merged commit 0a35363 into NVIDIA:main Jul 22, 2024
6 checks passed
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.

5 participants