Repository navigation
fix(pcapng): walk the journal entry instead of splitting it on b'\n\n' - #728
Conversation
42933aa to
d23bffa
Compare
|
❌ NEEDS CHANGES @ |
|
❌ NEEDS CHANGES @ First independent review, different model from the author. Everything below is evidence I obtained myself.
Required change. The reader's position is well defined after a bad terminator, so bailing is a policy choice, not a necessity — and it is the shape this docstring's own #678 note argues against ("aborted the whole extraction rather than this one entry"), one level down. Either drop Minor, not blocking. Counts (repo venv 3.14.7, ❌ NEEDS CHANGES @ |
- SystemdJournalExportBlock.post_process split self.entry on b'\n\n' before reading a field, delimiting a length-prefixed format by content. A binary value containing b'\n\n' was cut mid-value into a bogus field in a spurious entry (#723 defect A); a 2,570-octet value is worse, since struct.pack('<Q', 2570) starts with b'\n\n', landing the split inside the length prefix and reading zero fields (defect B). - Rewrote the loop to walk self.entry once, length-prefix driven; folds in #722's terminator check so both fixes coexist, and retires its newline-restoration, which only undid what slicing had taken away. - A trailing separator landing on the block's last octet was indistinguishable from plain EOF and swallowed instead of ending the entry, writing a rebuilt length one octet short. Now tracked so a real blank line still starts the next entry. - Cross-review found the added `malformed` flag broke the *outer* per-entry loop, widening #722's per-entry terminator check into a per-block one and silently dropping well-formed entries behind a bad one. Removed it; the existing `break` already scopes the check to its own entry. Its `:1832` twin was already dead (EOF-only, where the walk ends regardless) -- confirmed and dropped too. - Tests for both #723 defects, #722's fixtures, the alignment gap, and a well-formed entry surviving a bad terminator ahead of it. Tests: 86 passed, 1753 subtests; pcapng.py coverage stays 100% statements/branches (551/78).
d23bffa to
dcd4808
Compare
|
Fixed @ Added two tests pinning behaviour relative to Abort-the-block-on-any-corruption was considered as deliberate hardening and rejected as the 86 passed, 1753 subtests branch-only; 92 passed, 2113 subtests merged into |
|
✅ GOOD TO MERGE @ |
|
✅ GOOD TO MERGE @ Second review; supersedes the ❌ NEEDS CHANGES on
Counts reproduced independently: branch-only 86 passed / 1753 subtests, Round-trip — and the rebuild is Caveats, none blocking: (a) no round-trip test exercises the rebuild path with empty entries present; (b) #728 walks into the block's NUL padding in more situations, so padding adjacent to non-NUL garbage can synthesise an empty-key junk field ✅ GOOD TO MERGE @ |
`_journal_entry`'s docstring in examples/generators/pcapng.py cited pcapkit/protocols/schema/misc/pcapng.py:1376 for the padding-splitting defect its alignment workaround exists to avoid. That line number was correct when the comment was written, but the defect itself was fixed earlier than the citation implied and by a different change than first attributed here. - The fix is #699 (closing #678): it added the `not line.strip(b'\x00')` guard that ends a journal entry on its own NUL padding instead of misreading it as a binary field name. #728/#723 only moved that guard while rewriting the parser to walk `self.entry` instead of splitting it -- confirmed with `git log -S "strip(b'\x00')"` and by diffing 8af2cfd against 73b8cc8. #723 is about content shredded by the `b'\n\n'` split, a different symptom. - Cite the fix and the mechanism instead of a bare line number. - Say the workaround stays because dropping it regenerates the untracked `test.pcapng` fixture (examples/captures/* is gitignored), not because it touches committed bytes -- and say the measurement found no `SchemaWarning`, not "no warning": an unrelated `ExtractionWarning: EOF reached` fires on the aligned entry too. - Fix `_Blocks.journal`'s docstring, which credited "the caller" for padding `entry` when `_Blocks.block` does it. Measured directly: built a misaligned journal entry through the real _Blocks writer, bypassing _journal_entry's alignment loop, and parsed it with the current Extractor -- one entry, zero SchemaWarnings, on both the aligned and misaligned forms. make isort and pytest tests/protocols/misc/test_pcapng_unit.py (88 passed, 1 skipped, 1753 subtests) both clean. Closes #791
`_journal_entry`'s docstring in examples/generators/pcapng.py cited pcapkit/protocols/schema/misc/pcapng.py:1376 for the padding-splitting defect its alignment workaround exists to avoid. That line number was correct when the comment was written, but the defect itself was fixed earlier than the citation implied and by a different change than first attributed here. - The fix is #699 (closing #678): it added the `not line.strip(b'\x00')` guard that ends a journal entry on its own NUL padding instead of misreading it as a binary field name. #728/#723 only moved that guard while rewriting the parser to walk `self.entry` instead of splitting it -- confirmed with `git log -S "strip(b'\x00')"` and by diffing 8af2cfd against 73b8cc8. #723 is about content shredded by the `b'\n\n'` split, a different symptom. - Cite the fix and the mechanism instead of a bare line number. - Say the workaround stays because dropping it regenerates the untracked `test.pcapng` fixture (examples/captures/* is gitignored), not because it touches committed bytes -- and say the measurement found no `SchemaWarning`, not "no warning": an unrelated `ExtractionWarning: EOF reached` fires on the aligned entry too. - Fix `_Blocks.journal`'s docstring, which credited "the caller" for padding `entry` when `_Blocks.block` does it. Measured directly: built a misaligned journal entry through the real _Blocks writer, bypassing _journal_entry's alignment loop, and parsed it with the current Extractor -- one entry, zero SchemaWarnings, on both the aligned and misaligned forms. make isort and pytest tests/protocols/misc/test_pcapng_unit.py (88 passed, 1 skipped, 1753 subtests) both clean. Closes #791
…793) `_journal_entry`'s docstring in examples/generators/pcapng.py cited pcapkit/protocols/schema/misc/pcapng.py:1376 for the padding-splitting defect its alignment workaround exists to avoid. That line number was correct when the comment was written, but the defect itself was fixed earlier than the citation implied and by a different change than first attributed here. - The fix is #699 (closing #678): it added the `not line.strip(b'\x00')` guard that ends a journal entry on its own NUL padding instead of misreading it as a binary field name. #728/#723 only moved that guard while rewriting the parser to walk `self.entry` instead of splitting it -- confirmed with `git log -S "strip(b'\x00')"` and by diffing 8af2cfd against 73b8cc8. #723 is about content shredded by the `b'\n\n'` split, a different symptom. - Cite the fix and the mechanism instead of a bare line number. - Say the workaround stays because dropping it regenerates the untracked `test.pcapng` fixture (examples/captures/* is gitignored), not because it touches committed bytes -- and say the measurement found no `SchemaWarning`, not "no warning": an unrelated `ExtractionWarning: EOF reached` fires on the aligned entry too. - Fix `_Blocks.journal`'s docstring, which credited "the caller" for padding `entry` when `_Blocks.block` does it. Measured directly: built a misaligned journal entry through the real _Blocks writer, bypassing _journal_entry's alignment loop, and parsed it with the current Extractor -- one entry, zero SchemaWarnings, on both the aligned and misaligned forms. make isort and pytest tests/protocols/misc/test_pcapng_unit.py (88 passed, 1 skipped, 1753 subtests) both clean. Closes #791
Please follow the guide below
make pylint,make mypy,make isort)make testpasses, and a test case covers the changeWhat is the purpose of your pull request?
fix— corrects a defectDescription of your pull request and other information
Fixes #723.
First review caught a regression against #722: the
malformedflag this rewrite added brokethe outer per-entry loop, so a bad terminator ended the whole block, not just its entry --
silently dropping every well-formed entry behind it, contradicting the "nothing of #722's is
lost" claim this PR originally made. Fixed by dropping
malformedentirely (its:1832twinwas already dead); the existing per-entry
breakis now the only effect. Alternative consideredand rejected as the default: abort the rest of the block on any corruption, as deliberate
hardening -- open for the maintainer to reconsider.
Also fixes an independent alignment gap: a trailing separator landing on the block's last octet
was indistinguishable from EOF and swallowed, so a rebuild wrote
lengthone octet short.Tests:
tests/protocols/misc/test_pcapng_unit.py, 86 passed, 1753 subtests.Coverage:
pcapng.py100% stmts/branches (551/78).