You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Strictness is the library's security story: we raise where scapy
silently fills defaults. But every exception carries only a formatted
string. Verified — the full attribute set on a raised TruncatedHeaderError is args, add_note, with_traceback. There is
no offset, no field, no protocol, no expected/actual.
Ethernet TruncatedHeaderError "Ethernet header needs 14 bytes, buffer holds 4"
IPv4 InvalidFieldError "IPv4 IHL must be at least 5, got 0"
Everything useful is in the prose. A fuzzing harness, a conformance
suite or a protocol-validation tool that wants to know where a parse
failed has to regex our error messages.
Why this is a differentiator, not just a nicety
Scapy mostly does not raise at all. dpkt raises bare UnpackError / NeedData with nothing attached. For the audience we most want —
people parsing untrusted input — this is the difference between a
library that rejects bad input and one that explains it. No
competitor offers it.
What to do
Add structured attributes to ProtocolError and populate them at every
raise site. Candidates: offset (byte offset into the buffer handed to decode), protocol (the class), field (name), expected, actual.
Design questions:
Offsets are per-decode()-call, since each layer receives its own
buffer slice. An offset absolute to the original frame needs the walker
(Ship decode_frame() — the chain walker belongs in the library #88) to add its cursor. Decide whether the exception carries a
relative offset that decode_frame rebases, or whether both are
exposed.
Keep the message strings as they are — they are good, and tests
assert on some of them.
Acceptance criteria
Every ProtocolError raised from src/ carries at least protocol and, where meaningful, offset and field.
Existing message text is unchanged.
decode_frame rebases relative offsets to the whole frame, or
documents why it does not.
Target: 2.0.0 (Tier 2 — from codec to platform)
Strictness is the library's security story: we raise where scapy
silently fills defaults. But every exception carries only a formatted
string. Verified — the full attribute set on a raised
TruncatedHeaderErrorisargs,add_note,with_traceback. There isno
offset, nofield, noprotocol, noexpected/actual.Everything useful is in the prose. A fuzzing harness, a conformance
suite or a protocol-validation tool that wants to know where a parse
failed has to regex our error messages.
Why this is a differentiator, not just a nicety
Scapy mostly does not raise at all. dpkt raises bare
UnpackError/NeedDatawith nothing attached. For the audience we most want —people parsing untrusted input — this is the difference between a
library that rejects bad input and one that explains it. No
competitor offers it.
What to do
Add structured attributes to
ProtocolErrorand populate them at everyraise site. Candidates:
offset(byte offset into the buffer handed todecode),protocol(the class),field(name),expected,actual.Design questions:
decode()-call, since each layer receives its ownbuffer slice. An offset absolute to the original frame needs the walker
(Ship decode_frame() — the chain walker belongs in the library #88) to add its cursor. Decide whether the exception carries a
relative offset that
decode_framerebases, or whether both areexposed.
assert on some of them.
Acceptance criteria
ProtocolErrorraised fromsrc/carries at leastprotocoland, where meaningful,offsetandfield.decode_framerebases relative offsets to the whole frame, ordocuments why it does not.