Skip to content

Fix harmless signed integer overflow.#21251

Merged
opencv-pushbot merged 1 commit intoopencv:3.4from
vrabaud:3.4_bayer
Dec 14, 2021
Merged

Fix harmless signed integer overflow.#21251
opencv-pushbot merged 1 commit intoopencv:3.4from
vrabaud:3.4_bayer

Conversation

@vrabaud
Copy link
Copy Markdown
Contributor

@vrabaud vrabaud commented Dec 13, 2021

When computing:

t1 = (bayer[1] + bayer[bayer_step] + bayer[bayer_step+2] + bayer[bayer_step*2+1])*G2Y;

there is a T (unsigned short or char) multiplied by an int which can overflow.
Then again, it is stored to t1 which is unsigned so the overflow disappears.
Keeping all unsigned is safer.
We cannot test for that as the behavior is currently correct, just not safe.

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 other license that is incompatible with OpenCV
  • The PR is proposed to proper branch

When computing:
t1 = (bayer[1] + bayer[bayer_step] + bayer[bayer_step+2] + bayer[bayer_step*2+1])*G2Y;
there is a T (unsigned short or char) multiplied by an int which can overflow.
Then again, it is stored to t1 which is unsigned so the overflow disappears.
Keeping all unsigned is safer.
@opencv-pushbot opencv-pushbot merged commit 4eab85d into opencv:3.4 Dec 14, 2021
@vrabaud vrabaud deleted the 3.4_bayer branch December 15, 2021 11:53
@alalek alalek mentioned this pull request Dec 15, 2021
@alalek alalek mentioned this pull request Dec 30, 2021
@alalek alalek mentioned this pull request Feb 22, 2022
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.

3 participants