Files
systemd/test/units/TEST-04-JOURNAL.corrupted-journals.sh
T
Frantisek Sumsal 35eb598af2 compress: gracefully handle a truncated ZSTD frame
If a journal file contains a truncated ZSTD frame (i.e. a frame with
Frame_Content_Size > 0, but with not enough data in Data_Block),
ZSTD_decompressStream() would return a non-zero, non-error value. This
would then skip the error path in the ZSTD_isError() branch and we'd hit
the following assert:

$ build-local/journalctl -o cat --file zstd-truncated.journal
Assertion 'output.pos >= prefix_len + 1' failed at src/basic/compress.c:1236, function decompress_startswith_zstd(). Aborting.
Aborted                    (core dumped) build-local/journalctl -o cat --file zstd-truncated.journal

Let's handle this situation gracefully and return EBADMSG instead.

Also, add another journalctl invocation to the corrupted-journals test
that goes through the sd_journal_get_data() -> decompress_startswith_zstd()
code path which, among other things, covers the issue when run on the
provided journal file.
2026-04-20 09:37:13 +02:00

51 lines
2.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1-or-later
set -eux
set -o pipefail
JOURNAL_DIR="$(mktemp -d)"
REMOTE_OUT="$(mktemp -d)"
# tar on C8S doesn't support the --zstd option
unzstd --stdout "/usr/lib/systemd/tests/testdata/test-journals/afl-corrupted-journals.tar.zst" | tar -xC "$JOURNAL_DIR/"
while read -r file; do
filename="${file##*/}"
unzstd "$file" -o "$JOURNAL_DIR/${filename%.zst}.journal"
done < <(find /usr/lib/systemd/tests/testdata/test-journals/corrupted/ -name "*.zst")
# First, try each of them sequentially. Skip this part when running with plain
# QEMU, as it is excruciatingly slow
# Note: we care only about exit code 124 (timeout) and special bash exit codes
# >124 (like signals)
if [[ "$(systemd-detect-virt -v)" != "qemu" ]]; then
while read -r file; do
timeout 10 journalctl --file="$file" --boot >/dev/null || [[ $? -lt 124 ]]
timeout 10 journalctl --file="$file" --verify >/dev/null || [[ $? -lt 124 ]]
timeout 10 journalctl --file="$file" --output=export >/dev/null || [[ $? -lt 124 ]]
timeout 10 journalctl --file="$file" --grep=. >/dev/null || [[ $? -lt 124 ]]
timeout 10 journalctl --file="$file" --fields >/dev/null || [[ $? -lt 124 ]]
timeout 10 journalctl --file="$file" --list-boots >/dev/null || [[ $? -lt 124 ]]
if [[ -x /usr/lib/systemd/systemd-journal-remote ]]; then
timeout 10 /usr/lib/systemd/systemd-journal-remote \
--getter="journalctl --file=$file --output=export" \
--split-mode=none \
--output="$REMOTE_OUT/system.journal" || [[ $? -lt 124 ]]
timeout 10 journalctl --directory="$REMOTE_OUT" >/dev/null || [[ $? -lt 124 ]]
rm -f "$REMOTE_OUT"/*
fi
done < <(find "$JOURNAL_DIR" -type f)
fi
# And now all at once
timeout 30 journalctl --directory="$JOURNAL_DIR" --boot >/dev/null || [[ $? -lt 124 ]]
timeout 30 journalctl --directory="$JOURNAL_DIR" --verify >/dev/null || [[ $? -lt 124 ]]
timeout 30 journalctl --directory="$JOURNAL_DIR" --output=export >/dev/null || [[ $? -lt 124 ]]
timeout 30 journalctl --directory="$JOURNAL_DIR" --grep=. >/dev/null || [[ $? -lt 124 ]]
timeout 30 journalctl --directory="$JOURNAL_DIR" --fields >/dev/null || [[ $? -lt 124 ]]
timeout 30 journalctl --directory="$JOURNAL_DIR" --list-boots >/dev/null || [[ $? -lt 124 ]]
if [[ -x /usr/lib/systemd/systemd-journal-remote ]]; then
timeout 30 /usr/lib/systemd/systemd-journal-remote \
--getter="journalctl --directory=$JOURNAL_DIR --output=export" \
--split-mode=none \
--output="$REMOTE_OUT/system.journal" || [[ $? -lt 124 ]]
timeout 30 journalctl --directory="$REMOTE_OUT" >/dev/null || [[ $? -lt 124 ]]
rm -f "$REMOTE_OUT"/*
fi