Repository navigation
packet: set zeroCopy in NewZeroCopyPacketSource - #172
Conversation
NewZeroCopyPacketSource never set the zeroCopy field, so the check in PacketsCtx that rejects a zero copy source combined with NoCopy could never fire. Set the field and add tests for the check. Fixes gopacket#74
This reverts commit f8c0188. Setting zeroCopy armed the panic in PacketsCtx, so programs that call Packets() on a zero copy source with NoCopy set, which ran before, now crash after upgrading. A patch release must not turn working code into a panic. The overwrite risk #74 describes stays until a fix that does not fail at runtime. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Reverting this. The change is correct and does what the check was meant to do. The problem is what it means for existing users. A program that creates a source with The overwrite risk this PR addresses is real, so I've reopened the issue. A fix we'd take is one that never fails at runtime. For example, the channel path could copy each packet's data before decoding when the source is zero copy, so |
|
Thanks for explaining the compatibility concern. Enabling the panic would break existing channel users during an upgrade. Copying the packet bytes before decoding on the channel path sounds like a better direction, while retaining zero-copy behavior for synchronous reads. A follow-up should test that queued packets remain stable as the source buffer is reused and that existing |
NewZeroCopyPacketSource never set the PacketSource zeroCopy field, so the
check in PacketsCtx that rejects a zero copy source combined with the NoCopy
decode option could never fire. This sets the field and adds tests for the
check, using a fake ZeroCopyPacketDataSource.
Behaviour change: a PacketSource created with NewZeroCopyPacketSource and
NoCopy enabled now panics when Packets() or PacketsCtx() is called, as the
check intended. Before, such callers silently got a buffered channel whose
packet data could be overwritten by later reads. NextPacket() is unaffected,
and so are zero copy sources without NoCopy.
Fixes #74