The vulnerability analysis focused on the provided commit patch, which addresses several security issues within the psd-tools compression module. The root cause of the vulnerabilities lies in the improper handling of compressed image data and metadata.
The most critical issue was found in the decompress function, which was susceptible to a ZIP bomb attack due to an unguarded call to zlib.decompress. This could lead to memory exhaustion and a denial-of-service. The same function also failed to validate image dimensions (width, height, depth) before memory allocation, potentially causing crashes when processing maliciously crafted files with extremely large dimensions.
Further analysis of the RLE decompression logic in both the Python (rle.py) and Cython (_rle.pyx) implementations revealed that they were not robust against malformed data. Invalid RLE data would cause the decoder to raise an exception, leading to an unhandled crash and another denial-of-service vector. The Cython implementation also contained a latent type-mismatch bug that could theoretically lead to an infinite loop.
The patch addresses these issues by:
- Introducing a
_safe_zlib_decompress function that enforces a maximum output size to prevent ZIP bombs.
- Adding explicit validation for image dimensions in the
decompress function.
- Replacing a runtime
assert with a proper ValueError check.
- Making the RLE decoders tolerant to errors by clipping data and padding instead of crashing.
- Fixing the type mismatch in the Cython decoder.
By identifying the functions where these changes were made, we can pinpoint the exact locations of the vulnerabilities.