Skip to content

Fixes #28396 : out-of-bounds read in SIMD type conversion#28397

Merged
asmorkalov merged 5 commits intoopencv:4.xfrom
0AnshuAditya0:fix-simd-oob-read-28396
Mar 27, 2026
Merged

Fixes #28396 : out-of-bounds read in SIMD type conversion#28397
asmorkalov merged 5 commits intoopencv:4.xfrom
0AnshuAditya0:fix-simd-oob-read-28396

Conversation

@0AnshuAditya0
Copy link
Copy Markdown
Contributor

@0AnshuAditya0 0AnshuAditya0 commented Jan 13, 2026

Fixes #28396
Fixes #27080

The vx_load_expand function in WASM intrinsics was using
wasm_v128_load which always loads a full 128-bit register
(16 bytes), even when the function only needed 8 elements.

For example, when converting uint8 to float32:

  • vx_load_expand needs 8 uint8 elements
  • But wasm_v128_load reads 16 bytes from memory
  • This causes an 8-byte out-of-bounds read

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

Copy link
Copy Markdown
Contributor

@akretz akretz left a comment

Choose a reason for hiding this comment

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

This seems to be the correct approach to fix the linked issue to me. Some observations:

  • You need the backslashes at the end of the lines, otherwise the macro breaks.
  • Don't you need to make the tmp array hold elements of type _Tpwvec::lane_type and then remove the call to intrin()? That's how it's done in the float16 implementation of v_load_expand. Because now the wasm_v128_load() reads over the end of the array.
  • v_load_expand_q has the same bug that it reads too much data, right? In that case, a similar fix has to be applied there.

@0AnshuAditya0
Copy link
Copy Markdown
Contributor Author

Switched the temp buffer to _Tpwvec::lane_type and load directly into the vector, consistent with the float16 implementation. This guarantees safe 128-bit loads on WASM and resolves the ASAN OOB. Also fixed macro formatting and applied the same fix to v_load_expand_q.

@0AnshuAditya0
Copy link
Copy Markdown
Contributor Author

@asmorkalov reminder that this is pending review. Let me know if I should address any changes.

@asmorkalov asmorkalov self-assigned this Feb 14, 2026
@asmorkalov asmorkalov force-pushed the fix-simd-oob-read-28396 branch from 44b9351 to aef1692 Compare February 14, 2026 10:15
@asmorkalov
Copy link
Copy Markdown
Contributor

Rebased on top of 4.x to re-trigger CI.

@asmorkalov asmorkalov merged commit c7732e1 into opencv:4.x Mar 27, 2026
26 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.

Out-of-bounds read in cvt_ in convert.simd.hpp normL1 does not give consistent results with different compilers and optimization levels

3 participants