Skip to content

Commit

Permalink
Add warning for OBJECT_UNUSED in journal plugin (#971)
Browse files Browse the repository at this point in the history
  • Loading branch information
JSCU-CNI authored Jan 16, 2025
1 parent f774c22 commit a8a085c
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 2 deletions.
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 @@ def __iter__(self) -> Iterator[dict[str, int | str]]:
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}")

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

0 comments on commit a8a085c

Please sign in to comment.