Repository navigation
fix(pcapng): parse a raw bytes block given to make() (#2354) - #2360
Muhtasim-Munif-Fahim wants to merge 1 commit into
Conversation
PCAPNG.unpack() overrides Protocol.unpack() without its handling of a made header that holds raw octets, so make(block=<bytes>) reached read() with bytes where the block schema was expected and raised a bare AttributeError. Re-parse the packed octets as a block read from a capture would be, and raise ProtocolError when they describe no block.
|
Review: NEEDS CHANGES at 1. SHB still fails. 2. Two comments are now false. The 3. The new test's module docstring narrates the old defect and repeats "every block type," which isn't true yet (see #1). Reword once SHB is fixed, or scope the claim to what's actually covered. What I verified independently and holds:
Non-blocking notes:
|
|
Heads up: our own PR #2370 (fix(pcapng): handle make(block=) for a DSB) also closes #2354, covers the DSB case this PR fixes, and is CI-green with no open review findings. If this PR's SHB gap and the conflicts above aren't addressed first, #2370 is likely to land ahead of it — not a reason to stop working on this one, just flagging the overlap. |
Please follow the guide below
make pylint,make mypy,make isort)make testpasses, and a test case covers the changedocs/source/changelog/and regeneratedCHANGELOG.md, if the change is user-visibleWhat is the purpose of your pull request?
fix— corrects a defectfeat— adds a featureperf— changes performance, not behaviourrefactor— changes neither behaviour nor performancetest— tests onlydocs— documentation onlyci— workflows or build toolingrelease— bumps the version or rolls up a distributionchore— anything elseDescription of your pull request and other information
Fixes #2354
PCAPNG.unpack()overridesProtocol.unpack()but skips its handling of a made header that holds raw octets. SoPCAPNG.make(block=<bytes>)packs the bytes verbatim, thenread()getsbyteswhere it expects the block schema, and fails with a bareAttributeErroronschema.block.length.Change (
pcapkit/protocols/misc/pcapng.py): at the top ofPCAPNG.unpack(), if the made header'sblockis rawbytes, drop the made header and parse the packed octets the same way a block read from a capture is parsed. Thenmake(block=<bytes>)builds the block the octets describe. If the octets describe no block (for exampleb''orbytes(8)), it raisesProtocolError('PCAPNG: malformed raw block given to make(): ...'). This matches whatProtocol.unpack()does for a raw item it cannot parse.Tests: new
tests/protocols/misc/test_pcapng_raw_bytes_block_2354_unit.py(built on thePCAPNGTestCasebase fromtest_pcapng_roundtrip2_unit):make(block=<raw octets>)gives the same block as parsing those octets;b''andbytes(8)raiseProtocolError.Checks run locally:
isort -l100 -ppcapkit --check-onlyis clean.pylint(Makefile flags) onpcapng.py: same message count asmain.mypy(Makefile flags) onpcapng.py: same errors asmain, with nothing new.pytest -n 8 --ignore=tests/integration, runtime/regression excluded): 5299 passed.maincheckout in my environment (tests/project/test_public_api.py,test_module_isolation.py, and sometests/constandtests/vendormodules). Runtime/regression tiers need the generated sample captures, which I don't have locally.pcapng/make/rawunit tests pass.Building a DSB from a dict with
bytessecrets_datais a separate bug, already covered by #2346, so the tests use hand-built raw octets instead.AI assistance: this change was prepared with help from an AI coding assistant and reviewed and tested by me before submission.