decompress_startswith() decodes just enough of a blob to compare its leading bytes against a prefix, and grows the output buffer whenever a round of decoding came back with less than prefix_len + 1 bytes decoded. That growth is only the right answer while the decoder actually wants more output room. If it instead ran out of input, i.e. the stream is truncated, then no amount of extra room will help, and the gzip and bzip2 paths double their allocation on every iteration until the process is out of memory. Neither decoder lets us tell the two cases apart by return code alone: inflate() reports the stalled stream as Z_BUF_ERROR, which we cannot simply refuse since that is also how it asks for a bigger output buffer, and BZ2_bzDecompress() does not distinguish them at all, it just keeps saying BZ_OK. The output space left over does tell us, though: a decoder that stopped without filling the buffer we gave it is waiting for input that is not coming, so report the stream as corrupt instead of growing. A 10 byte gzip header, or a 4 byte bzip2 header, with nothing behind it was enough to reach a single 4 GiB allocation this way. The xz and zstd paths already terminate, the former because liblzma turns a stalled stream into LZMA_BUF_ERROR. Note that no caller can reach this today: the only non-test caller is decompress_startswith_journal(), and compression_supported_journal() admits only NONE/XZ/LZ4/ZSTD. It is a trap for whoever wires up the other two, so let's close it now.
System and Service Manager
Details
Most documentation is available on systemd's website.
Assorted, older, general information about systemd can be found in the systemd Wiki.
Information about build requirements is provided in the README file.
Consult our NEWS file for information about what's new in the most recent systemd versions.
Please see the Code Map for information about this repository's layout and content.
Please see the Hacking guide for information on how to hack on systemd and test your modifications.
Please see our Contribution Guidelines for more information about filing GitHub Issues and posting GitHub Pull Requests.
When preparing patches for systemd, please follow our Coding Style Guidelines.
If you are looking for support, please contact our mailing list, join our IRC channel #systemd on libera.chat or Matrix channel
Stable branches with backported patches are available in the stable repo.
We have a security bug bounty program sponsored by the Sovereign Tech Fund hosted on YesWeHack
Repositories with distribution packages built from git main are available on OBS, and also repositories with packages built from the latest stable release
