Skip to content

Commit a8a085c

Browse files
authored
Add warning for OBJECT_UNUSED in journal plugin (#971)
1 parent f774c22 commit a8a085c

File tree

5 files changed

+55
-2
lines changed

5 files changed

+55
-2
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,18 @@ def __iter__(self) -> Iterator[dict[str, int | str]]:
315315
offset = self.header.entry_array_offset
316316
while offset != 0:
317317
self.fh.seek(offset)
318+
object_type = self.fh.read(1)[0]
318319

319-
if self.fh.read(1)[0] != c_journal.ObjectType.OBJECT_ENTRY_ARRAY:
320-
raise ValueError(f"Expected OBJECT_ENTRY_ARRAY at offset {offset}")
320+
if object_type == c_journal.ObjectType.OBJECT_UNUSED:
321+
self.target.log.warning(
322+
"ObjectType OBJECT_UNUSED encountered for next OBJECT_ENTRY_ARRAY offset at 0x%X. "
323+
"This indicates allocated space in the journal file which is not used yet.",
324+
offset,
325+
)
326+
break
327+
328+
elif object_type != c_journal.ObjectType.OBJECT_ENTRY_ARRAY:
329+
raise ValueError(f"Expected OBJECT_ENTRY_ARRAY or OBJECT_UNUSED at offset {offset}")
321330

322331
if self.header.incompatible_flags & c_journal.IncompatibleFlag.HEADER_INCOMPATIBLE_COMPACT:
323332
entry_array_object = c_journal.EntryArrayObject_Compact(self.fh)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:bd34a41863a93619bff6389d760dd3417652dc42083776bd8a13fa6a0725178e
3+
size 8388608
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:eb19305d131360a8b6ea15f8db3c906cb0bb10c92e2b29a3155cbbcf67cc53c2
3+
size 8388608
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:d5dfb012b37018e9c39826ab0f44cd583045964c417e19bbaacbaefa74122da0
3+
size 16777216

tests/plugins/os/unix/log/test_journal.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import logging
2+
3+
import pytest
14
from flow.record.fieldtypes import datetime as dt
25

36
from dissect.target.filesystem import VirtualFilesystem
@@ -28,3 +31,35 @@ def test_journal_plugin(target_unix: Target, fs_unix: VirtualFilesystem) -> None
2831
assert record.pid == 2096
2932
assert record.transport == "stdout"
3033
assert record.source == "/var/log/journal/1337/user-1000.journal"
34+
35+
36+
def test_journal_plugin_benchmark(target_unix: Target, fs_unix: VirtualFilesystem) -> None:
37+
"""test if we can parse some large journal files. this demonstrates how slow the journal plugin is."""
38+
39+
system_journal = absolute_path("_data/plugins/os/unix/log/journal/system.journal")
40+
user_journal = absolute_path("_data/plugins/os/unix/log/journal/user-1000.journal")
41+
42+
fs_unix.map_file("/var/log/journal/deadbeef/system.journal", system_journal)
43+
fs_unix.map_file("/var/log/journal/deadbeef/user-1000.journal", user_journal)
44+
target_unix.add_plugin(JournalPlugin)
45+
46+
results = list(target_unix.journal())
47+
assert len(results) == 252 + 17986
48+
49+
50+
def test_journal_plugin_unused_object(
51+
caplog: pytest.LogCaptureFixture, target_unix: Target, fs_unix: VirtualFilesystem
52+
) -> None:
53+
"""test if we can handle OBJECT_UNUSED in journal files correctly."""
54+
55+
# unused.journal is a modified copy of system.journal at offset 0x393260.
56+
# the next_entry_array_offset was set from 0x00 to 0x3C1337.
57+
data_file = absolute_path("_data/plugins/os/unix/log/journal/unused.journal")
58+
fs_unix.map_file("/var/log/journal/deadbeef/system.journal", data_file)
59+
target_unix.add_plugin(JournalPlugin)
60+
61+
with caplog.at_level(logging.WARNING):
62+
results = list(target_unix.journal())
63+
64+
assert "ObjectType OBJECT_UNUSED encountered for next OBJECT_ENTRY_ARRAY offset at 0x3C1337" in caplog.text
65+
assert len(results) == 252

0 commit comments

Comments
 (0)