Skip to content

Commit

Permalink
[FIX] Fixed heap corruption when copying a discontinuous cv::mat matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
LAGNEAU Romain committed Jan 22, 2025
1 parent e3dfc17 commit 75b9a00
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions modules/core/src/image/vpImageConvert_opencv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,12 @@ void vpImageConvert::convert(const cv::Mat &src, vpImage<unsigned char> &dest, b
else {
if (flip) {
for (unsigned int i = 0; i < destRows; ++i) {
memcpy(dest.bitmap + (i * destCols), src.data + ((destRows - i - 1) * src.step1()), static_cast<size_t>(src.step));
memcpy(dest.bitmap + (i * destCols), src.data + ((destRows - i - 1) * src.step1()), static_cast<size_t>(destCols * sizeof(unsigned char)));

Check warning on line 225 in modules/core/src/image/vpImageConvert_opencv.cpp

View check run for this annotation

Codecov / codecov/patch

modules/core/src/image/vpImageConvert_opencv.cpp#L225

Added line #L225 was not covered by tests
}
}
else {
for (unsigned int i = 0; i < destRows; ++i) {
memcpy(dest.bitmap + (i * destCols), src.data + (i * src.step1()), static_cast<size_t>(src.step));
memcpy(dest.bitmap + (i * destCols), src.data + (i * src.step1()), static_cast<size_t>(destCols * sizeof(unsigned char)));

Check warning on line 230 in modules/core/src/image/vpImageConvert_opencv.cpp

View check run for this annotation

Codecov / codecov/patch

modules/core/src/image/vpImageConvert_opencv.cpp#L230

Added line #L230 was not covered by tests
}
}
}
Expand Down Expand Up @@ -365,12 +365,12 @@ void vpImageConvert::convert(const cv::Mat &src, vpImage<uint16_t> &dest, bool f
else {
if (flip) {
for (unsigned int i = 0; i < destRows; ++i) {
memcpy(dest.bitmap + (i * destCols), src.data + ((destRows - i - 1) * src.step1() * sizeof(uint16_t)), static_cast<size_t>(src.step));
memcpy(dest.bitmap + (i * destCols), src.data + ((destRows - i - 1) * src.step1() * sizeof(uint16_t)), static_cast<size_t>(destCols * sizeof(uint16_t)));

Check warning on line 368 in modules/core/src/image/vpImageConvert_opencv.cpp

View check run for this annotation

Codecov / codecov/patch

modules/core/src/image/vpImageConvert_opencv.cpp#L368

Added line #L368 was not covered by tests
}
}
else {
for (unsigned int i = 0; i < destRows; ++i) {
memcpy(dest.bitmap + (i * destCols), src.data + (i * src.step1() * sizeof(uint16_t)), static_cast<size_t>(src.step));
memcpy(dest.bitmap + (i * destCols), src.data + (i * src.step1() * sizeof(uint16_t)), static_cast<size_t>(destCols * sizeof(uint16_t)));
}
}
}
Expand Down

0 comments on commit 75b9a00

Please sign in to comment.