Repository navigation
Commit 3d29238
committed
fix(pcapng): resolve byte order for a raw bytes option without self._byte set (#2353)
An option or record handed to a block maker as raw bytes has its type code read
back out of those octets, in the block's byte order -- which only
`_make_block_shb` and `_make_block_systemd` set. A raw option in any other
block, and a raw record in an NRB, therefore raised `AttributeError: 'PCAPNG'
object has no attribute '_byte'`.
`make` now settles the byte order before the block maker runs, the way `pack`
settles it: the section's, else the one the packet data declares, else the
host's. A section header block still overrides it from its own Byte-Order
Magic. Settling it here covers every block maker: `_make_block_shb` and
`_make_block_systemd` settle their own, and without this the rest read an
attribute that is not there.
`__packet__` handed over as `None` degrades to no packet data, matching how
`Schema.pack` already treats it, rather than raising a `TypeError`.
Tested by a unit module: a raw option and a raw record build with no byte
order set, each block parses back from its own octets and rebuilds byte for
byte, the code resolved is pinned through the "only one of this option" guard
in a big-endian section as well as a little-endian one, a bound section
outranks a byte order the packet data declares, a byte order declared one
level up inside `__packet__` is read correctly, and `__packet__=None` resolves
to the host order instead of raising.
Fail-without-fix: 10 test methods, 16 failures on `origin/main`.1 parent 7886d9f commit 3d29238
2 files changed
Lines changed: 380 additions & 0 deletions
File tree
- pcapkit/protocols/misc
- tests/protocols/misc
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| 67 | + | |
67 | 68 | | |
68 | 69 | | |
69 | 70 | | |
| |||
1457 | 1458 | | |
1458 | 1459 | | |
1459 | 1460 | | |
| 1461 | + | |
| 1462 | + | |
| 1463 | + | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
1460 | 1482 | | |
1461 | 1483 | | |
1462 | 1484 | | |
| |||
0 commit comments