Panics and aborts when reading crafted 7z archives
Description
sevenz-rust2 can panic or abort the process when it reads a crafted 7z archive. This can happen when the archive is opened and when its entries are decoded. An attacker who can supply an archive to a program that uses this crate can crash that program.
- Crate:
sevenz-rust2 - Affected versions: all versions up to and including 0.24.1
- Patched version: 0.24.2
Impact
A program that reads untrusted 7z archives with sevenz-rust2 can crash on a crafted archive.
All functions that open an archive or decode its entries are affected. This includes the extraction functions of the util feature and the WASM decompress function.
Issues
The advisory covers four groups of issues.
- Inconsistent header structure. The crate accepted archive headers whose parts did not fit together. Examples are a header that describes compressed data without a list of files, a compression block without packed data, and a coder without exactly one output stream. Decoding such an archive panicked.
- Unbounded coder graphs. The crate accepted compression blocks with very long chains of coders and blocks that use a stream more than once. Decoding such a block could overflow the stack or exhaust memory.
- Memory allocation from header values. The crate allocated memory for counts and sizes from the archive header with allocations that abort or panic when they fail. A crafted header could declare counts that exceed the address space or the available memory. Some error paths also allocated memory after an allocation had failed.
- Platform-specific panics. The WASM
decompressfunction panicked when an archive pointed past the end of its data. On Windows, the extraction functions of theutilfeature panicked on a file time outside the range of the platform'sSystemTime.
The patched version rejects such archives with an error. It returns an error when an allocation for header data fails, and it leaves file times unset when the platform cannot hold them.
Mitigation
Update sevenz-rust2 to 0.24.2 or later.