google / zopfli

Zopfli Compression Algorithm is a compression library programmed in C to perform very good, but slow, deflate or zlib compression.
Apache License 2.0
3.43k stars 330 forks source link

Multiplication result converted to larger type (Mitigate Arithmetic Overflow in Memory Allocation) #198

Closed Shivam7-1 closed 7 months ago

Shivam7-1 commented 9 months ago

In This PR a potential vulnerability related to arithmetic overflow in the lodepng_malloc call. The multiplication of w * h * (bit16 ? 8 : 4) might result in overflow before the conversion to size_t, leading to unexpected behavior or security risks.

Modified the code to ensure safe multiplication by explicitly casting w and h to size_t before performing the arithmetic operation.

The explicit casting to size_t helps prevent arithmetic overflow by ensuring that the multiplication is performed using a larger integer type, reducing the risk of unexpected behavior or security vulnerabilities, especially in memory allocation scenarios.

Exact Security Issue: Arithmetic overflow can lead to allocating less memory than required, which can cause buffer overflows when the memory is accessed. Buffer overflows are well-known security vulnerabilities that can be exploited to execute arbitrary code, cause a program to crash, or lead to other undefined behavior.

Shivam7-1 commented 8 months ago

hi @google-admin Could anyone Review above PR Thanks

Shivam7-1 commented 8 months ago

Hi @lvandeve Could You Please Review Above PR

Thanks & Regards

jibsen commented 7 months ago

Not a maintainer of this project, but just a few observations about your PR: