Skip to content

pcapng: a journal entry without a trailing newline returns the block padding as field data #794

Closed

Description

@JarryShaw

Describe the bug

A systemd journal entry whose last field has no trailing newline absorbs the PCAP-NG block padding into that field's value, silently. Measured on ef859f776:

raw = b'MESSAGE=hello' + b'\x00\x00\x00'   # 13-octet entry + the 3 NULs block() appends
SystemdJournalExportBlock.post_process(...)
-> [OrderedMultiDict([('MESSAGE', 'hello\x00\x00\x00')])]

The three NUL octets are the block's own 4-octet alignment padding, and they come back as data. No exception, no SchemaWarning, nothing a caller could branch on.

Why the existing guard misses it

pcapkit/protocols/schema/misc/pcapng.py:1857 ends the entry when a line strips to nothing but NULs:

if not line.strip(b'\x00'):
    break

That fires only when the NULs form their own line — i.e. when the entry ended with \n and the padding follows it. With no trailing newline the NULs are part of the final field's line, so the guard never sees them and bytes.strip() does not treat NUL as whitespace.

Expected behavior

Either strip the trailing NULs from the last field's value, or refuse the entry with a ProtocolError from pcapkit.utilities.exceptions. Returning alignment padding as field data is the one option that should not survive.

The format does require the trailing newline, so this is malformed input — but "malformed input silently yields corrupted data" is worse than either alternative, and a caller reading MESSAGE has no way to know the NULs are not the sender's.

Additional context

Found by the cross-review on #793 while checking whether the padding defect that PR describes is genuinely gone. It is — for the newline-terminated case, fixed by #699 (8af2cfda7), which added the NUL-only-line guard. This is the adjacent case that guard does not cover.

Distinct from #704 (every field after the first binary field discarded) and from #723 (the b'\n\n' split shredding binary values), both closed. Related: #793, #791.

Activity

  1. added
    bugIssues reporting a defect (set by the bug report template; a default, not an assessment)
    fixPull requests that fix a defect (fix: subject prefix)
    wipWork in flight - a covering PR is open or an agent is actively on it
    on Sep 25, 2026
  2. added 2 commits that reference this issue on Sep 25, 2026
    5226a03
    5777a93
  3. removed
    wipWork in flight - a covering PR is open or an agent is actively on it
    on Sep 25, 2026
  4. added this to the 1.5 milestone on Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssues reporting a defect (set by the bug report template; a default, not an assessment)fixPull requests that fix a defect (fix: subject prefix)

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions