Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add warning for OBJECT_UNUSED in journal plugin #971

Merged
merged 5 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions dissect/target/plugins/os/unix/log/journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,18 @@
offset = self.header.entry_array_offset
while offset != 0:
self.fh.seek(offset)
object_type = self.fh.read(1)[0]

if self.fh.read(1)[0] != c_journal.ObjectType.OBJECT_ENTRY_ARRAY:
raise ValueError(f"Expected OBJECT_ENTRY_ARRAY at offset {offset}")
if object_type == c_journal.ObjectType.OBJECT_UNUSED:
self.target.log.warning(
"ObjectType OBJECT_UNUSED encountered for next OBJECT_ENTRY_ARRAY offset at 0x%X. "
"This indicates allocated space in the journal file which is not used yet.",
offset,
)
break

elif object_type != c_journal.ObjectType.OBJECT_ENTRY_ARRAY:
raise ValueError(f"Expected OBJECT_ENTRY_ARRAY or OBJECT_UNUSED at offset {offset}")

Check warning on line 329 in dissect/target/plugins/os/unix/log/journal.py

View check run for this annotation

Codecov / codecov/patch

dissect/target/plugins/os/unix/log/journal.py#L329

Added line #L329 was not covered by tests

if self.header.incompatible_flags & c_journal.IncompatibleFlag.HEADER_INCOMPATIBLE_COMPACT:
entry_array_object = c_journal.EntryArrayObject_Compact(self.fh)
Expand Down
3 changes: 3 additions & 0 deletions tests/_data/plugins/os/unix/log/journal/system.journal
Git LFS file not shown
3 changes: 3 additions & 0 deletions tests/_data/plugins/os/unix/log/journal/unused.journal
Git LFS file not shown
3 changes: 3 additions & 0 deletions tests/_data/plugins/os/unix/log/journal/user-1000.journal
Git LFS file not shown
35 changes: 35 additions & 0 deletions tests/plugins/os/unix/log/test_journal.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import logging

import pytest
from flow.record.fieldtypes import datetime as dt

from dissect.target.filesystem import VirtualFilesystem
Expand Down Expand Up @@ -28,3 +31,35 @@ def test_journal_plugin(target_unix: Target, fs_unix: VirtualFilesystem) -> None
assert record.pid == 2096
assert record.transport == "stdout"
assert record.source == "/var/log/journal/1337/user-1000.journal"


def test_journal_plugin_benchmark(target_unix: Target, fs_unix: VirtualFilesystem) -> None:
"""test if we can parse some large journal files. this demonstrates how slow the journal plugin is."""

system_journal = absolute_path("_data/plugins/os/unix/log/journal/system.journal")
user_journal = absolute_path("_data/plugins/os/unix/log/journal/user-1000.journal")

fs_unix.map_file("/var/log/journal/deadbeef/system.journal", system_journal)
fs_unix.map_file("/var/log/journal/deadbeef/user-1000.journal", user_journal)
target_unix.add_plugin(JournalPlugin)

results = list(target_unix.journal())
assert len(results) == 252 + 17986


def test_journal_plugin_unused_object(
caplog: pytest.LogCaptureFixture, target_unix: Target, fs_unix: VirtualFilesystem
) -> None:
"""test if we can handle OBJECT_UNUSED in journal files correctly."""

# unused.journal is a modified copy of system.journal at offset 0x393260.
# the next_entry_array_offset was set from 0x00 to 0x3C1337.
data_file = absolute_path("_data/plugins/os/unix/log/journal/unused.journal")
fs_unix.map_file("/var/log/journal/deadbeef/system.journal", data_file)
target_unix.add_plugin(JournalPlugin)

with caplog.at_level(logging.WARNING):
results = list(target_unix.journal())

assert "ObjectType OBJECT_UNUSED encountered for next OBJECT_ENTRY_ARRAY offset at 0x3C1337" in caplog.text
assert len(results) == 252
Loading