Repository navigation
Conversation
| if parse_pcap_header(buffer.data()).is_err() { | ||
| let sz = reader.read(buffer.space()).or(Err(PcapError::ReadError))?; | ||
| buffer.fill(sz); | ||
| } |
There was a problem hiding this comment.
I think I understand the problem, however I am unsure of the solution.
Instead of parsing twice, can't we just check if buffer has PcapHeader::size() (24) bytes for the first call?
I don't think there are cases that could fail on that
There was a problem hiding this comment.
Updated in f5f8fc0: from_buffer now keeps the successfully parsed PcapHeader, avoiding the second parse. I kept the parser-based decision rather than a length-only gate so malformed prefills retain the existing refill and read-error precedence. The partial-header/read-count controls and all 66 all-feature unit/integration tests pass; the two existing doctest failures remain.
| if parse_sectionheaderblock(buffer.data()).is_err() { | ||
| let sz = reader.read(buffer.space()).or(Err(PcapError::ReadError))?; | ||
| buffer.fill(sz); | ||
| } |
There was a problem hiding this comment.
This double call is hard to avoid, because unlike pcap, the SHB has a variable size here.
Just thinking:
I'm just wondering if there is a way to keep the result and avoid calling the parser twice if it worked.
Or maybe I am over-optimizing ...
There was a problem hiding this comment.
Updated in f5f8fc0: the second SHB validation now runs only after a refill. A successful initial parse needs no second validation in from_buffer; the block remains buffered for next(). Added controls cover option-bearing variable-size SHBs in both byte orders, including partial prefills and exact read counts. Independent reader/error/lifecycle controls pass on the previous and final versions.
create_readerbuffers a complete header before callingfrom_buffer. Reading again there can fail on a full streaming-decoder buffer or wait for more input while the producer waits for the header to be processed. Reuse the buffered header in both PCAP and PCAPNG readers.Fixes #57.
The review follow-up reuses the parsed legacy header and validates PCAPNG again only after a refill. It preserves the existing refill/error behavior for malformed prefills. Added controls cover partial legacy headers and variable-size, option-bearing section headers in both byte orders.
Validation of
f5f8fc0: all 66 unit/integration tests with all features and all 52 without default features pass; formatting and nightly documentation pass. Independent public-reader controls pass on both the prior submitted version and this follow-up; current upstream still reproduces the redundant-read defect. The original four regressions failed on basea5ca3c6.Local full test commands still fail two existing doctests. Strict stable check reports nine existing warnings as errors; nightly Clippy reports eleven across each feature configuration. Clean-base comparisons retain those findings. The local Rust 1.65 check stops in dependency resolution (
web-sys/js-sys); local semver/external-type checks were not run. The reader fixtures model streaming behavior; no real zstd process or device testing is claimed.Current-head hosted CI: all three test configurations, formatting, documentation and semver pass. Strict nightly check and Clippy fail on the same existing diagnostics recorded above; the external-type checker fails on a rustdoc JSON format mismatch (55 produced, 57 required). The stable check job was canceled after its check step reported failure; Rust 1.65 was canceled during Cargo update. These results do not establish full green CI.