Skip to content
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

inflate.c: fix potential overflow in inflatePrime #1051

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

AntonMoryakov
Copy link

The condition state->bits + (uInt)bits > 32 was replaced with state->bits + (uInt)bits >= 32 to prevent potential overflow when shifting value by state->bits. A shift equal to or greater than the size of the data type (32 bits) can lead to undefined behavior.

This change ensures that the sum of state->bits and bits never reaches 32, avoiding the risk of overflow in the expression (unsigned)value << state->bits.

While the scenario leading to overflow is unlikely in practice due to the constraints of the calling function inflatePrime, I recommend applying this change to improve code robustness and adhere to safe coding practices. This is a preventive measure to eliminate any potential risks in edge cases.

Triggers found by static analyzer Svace.

Signed-off-by: Anton Moryakov [email protected]

The condition `state->bits + (uInt)bits > 32` was replaced with
`state->bits + (uInt)bits >= 32` to prevent potential overflow
when shifting `value` by `state->bits`. A shift equal to or greater
than the size of the data type (32 bits) can lead to undefined behavior.

This change ensures that the sum of `state->bits` and `bits` never
reaches 32, avoiding the risk of overflow in the expression
`(unsigned)value << state->bits`.

While the scenario leading to overflow is unlikely in practice
due to the constraints of the calling function `inflatePrime`,
I recommend applying this change to improve code robustness
and adhere to safe coding practices. This is a preventive measure
to eliminate any potential risks in edge cases.


Triggers found by static analyzer Svace.

Signed-off-by: Anton Moryakov <[email protected]>
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.

1 participant