Skip to content

Potential integer overflow at zlib/inflate.c #1090

Description

@samitistfobos-dev

Potential problem

In inflatePrime (zlib/inflate.c, 219), the expression value << state->bits (zlib/inflate.c, 232) is evaluated using the type of value, which is int. If the shifted result cannot be represented by int, signed integer overflow occurs and the behavior is undefined before the result is added to state->hold.
For example, with state->bits = 16, bits = 16, and value = 0xFFFF, the expression value << state->bits produces a value that cannot be represented by a 32-bit signed int.

Possible solution
It is suggested to cast value to unsigned long before performing the left shift:
state->hold += (unsigned long)value << state->bits;
This ensures that the shift is performed using an unsigned type large enough for the resulting value and prevents signed integer overflow.

Found by Linux Verification Center (portal.linuxtesting.ru) with SVACE.

Author A. Burlakov.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions