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
_make_param_solution sizes the SOLUTION parameter with math.ceil(bits / 4), which is an invalid shorthand for "two fields of ceil(bits/8) octets each". For any non-byte-aligned input it emits a parameter that this library's own reader then rejects.
The two sites
pcapkit/protocols/internet/hip.py:3200, in the builder:
pcapkit/protocols/internet/hip.py:1083-1084, in the reader:
if (schema.len-4) %2!=0:
raiseProtocolError(f'HIPv{version}: [ParamNo {schema.type}] invalid format')
Measured
On origin/main (493020f83), CPython 3.14.7:
random=0x1 solution=0xfff : current len=7 correct len=8 -> (7-4) % 2 != 0 REJECTED by its own reader
random=0xff solution=0xff : current len=6 correct len=6 -> accepted
So a build-then-parse round trip raises ProtocolError: HIPv2: [ParamNo 321] invalid format on input the builder itself produced.
Why / 4 is wrong rather than a nibble count
SolutionParameter sizes random and solution at (pkt['len'] - 4) // 2each — pcapkit/protocols/schema/internet/hip.py:454 and :456. So the length must be 4 + 2 × ceil(bits/8), two equal fields of whole octets.
ceil(x/4) coincides with 2 × ceil(x/8) only when x is a multiple of 8. The reader's own comment at hip.py:1090 records the shorthand —
— and it is valid there only because a real RHASH_len is a fixed multiple of 8. Substituting an arbitrary bit_length() breaks the identity, which is exactly what the builder does.
Every fixture and test that reaches this builder supplies byte-aligned values, where the two formulas agree. This is the third instance in this repository of the same blind spot: #591's repair-path suite used bit lengths 8/16/32/64/24, and #601's ILNP round-trip case uses nonce: 0xFFFFFF (bit length 24) at examples/generators/options.py:537. A test whose inputs are all multiples of 8 cannot distinguish a floor, a ceiling, or a quarter.
Two further hip.py items were reported alongside this and are NOT investigated, recorded here so they are not lost: the PUZZLE/SOLUTION builders recompute widths from bit_length() when re-serialising an already-parsed parameter, so leading zero octets would be lost on a parse-then-rebuild; and the readers compute padding from schema.len % 8 rather than from the total record length including the 4-octet header. Both are claims, unverified by me.
_make_param_solutionsizes the SOLUTION parameter withmath.ceil(bits / 4), which is an invalid shorthand for "two fields ofceil(bits/8)octets each". For any non-byte-aligned input it emits a parameter that this library's own reader then rejects.The two sites
pcapkit/protocols/internet/hip.py:3200, in the builder:pcapkit/protocols/internet/hip.py:1083-1084, in the reader:Measured
On
origin/main(493020f83), CPython 3.14.7:So a build-then-parse round trip raises
ProtocolError: HIPv2: [ParamNo 321] invalid formaton input the builder itself produced.Why
/ 4is wrong rather than a nibble countSolutionParametersizesrandomandsolutionat(pkt['len'] - 4) // 2each —pcapkit/protocols/schema/internet/hip.py:454and:456. So the length must be4 + 2 × ceil(bits/8), two equal fields of whole octets.ceil(x/4)coincides with2 × ceil(x/8)only whenxis a multiple of 8. The reader's own comment athip.py:1090records the shorthand —— and it is valid there only because a real
RHASH_lenis a fixed multiple of 8. Substituting an arbitrarybit_length()breaks the identity, which is exactly what the builder does.The correct expression:
Why nothing caught it
Every fixture and test that reaches this builder supplies byte-aligned values, where the two formulas agree. This is the third instance in this repository of the same blind spot: #591's repair-path suite used bit lengths 8/16/32/64/24, and #601's ILNP round-trip case uses
nonce: 0xFFFFFF(bit length 24) atexamples/generators/options.py:537. A test whose inputs are all multiples of 8 cannot distinguish a floor, a ceiling, or a quarter.Notes
/ 4was a deliberate nibble count. It established that it is not, and reported rather than fixing it becausehip.pywas outside its assigned files — the right call.// 2field sizing.numbers.pywidth repair, fixed in fix(corekit): size the width repair with a real ceiling, not a floored one (#599) #600).hip.pyitems were reported alongside this and are NOT investigated, recorded here so they are not lost: the PUZZLE/SOLUTION builders recompute widths frombit_length()when re-serialising an already-parsed parameter, so leading zero octets would be lost on a parse-then-rebuild; and the readers compute padding fromschema.len % 8rather than from the total record length including the 4-octet header. Both are claims, unverified by me.