Skip to content

fix(const): resolve every three-digit FTP reply and HTTP status code (#1443) - #1444

Merged
JarryShaw merged 1 commit into
mainfrom
fix/1443-unassigned-ftp-http-codes
Oct 9, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
fix/1443-unassigned-ftp-http-codes

Conversation

@JarryShaw

@JarryShaw JarryShaw commented Oct 9, 2026 •

Copy link
Copy Markdown
Owner

Closes #1443

Before: FTP(b'999 hi\r\n', 8), FTP(b'099 x\r\n', 7), HTTP(b'HTTP/1.1 999 X\r\n\r\n', 20) and ReturnCode.get(777) raise EnumValueError; 440/1000 FTP and 500/1000 HTTP codes fail to parse. After: all 1000 of each parse and rebuild byte-exact via from_data; values outside the registry range resolve to an Unknown pseudo-member (not registered), -1 and 1000 still raise. make() now writes the code zero-padded (099, not 99).

Vendor templates (pcapkit/vendor/{ftp/return_code,http/status_code}.py) carry the same change; rendering both crawlers offline from today's Wikipedia/IANA snapshots reproduces the committed const/ files byte-identically (and did so on main before the change).

Tests: tests/protocols/application/test_ftp_http_unassigned_code_1443_unit.py — 9 passed / 2017 subtests; with the source reverted, 7 of 9 tests fail (949 subtests). protocols --exclude protocols/internet leg: 1119 tests, 0 failures. tests/project: 419 passed, 1 skipped.

Existing test: tests/const/test_const_enum_lookup.py drops ReturnCode and StatusCode from EXPECTED_TO_REJECT_ZERO (#492), which pinned 0 raising. Both wire fields are three digits, so 000 now parses to an Unknown pseudo-member. const leg: 502 tests, 0 failures.

…1443)

ReturnCode resolved only 100-659 and StatusCode only 100-599, so a reply
such as `999 hi` or a status line such as `HTTP/1.1 999 X` raised
EnumValueError and could not be parsed. Both wire fields are three digits,
so 0-999 now resolve: inside the registry's range as before, outside it to
an `Unknown` pseudo-member. ReturnCode derives kind and group from the
zero-padded code, and FTP/HTTP make() write the code as three digits, so
`099` rebuilds byte for byte. The vendor templates carry the same change.
@JarryShaw JarryShaw added fix Pull requests that fix a defect (fix: subject prefix) const Regenerated IANA or vendor constant tables; members keep their numeric values review: pending No verdict for the current head - never reviewed, or the head moved since the last one labels Oct 9, 2026
@JarryShaw
JarryShaw force-pushed the fix/1443-unassigned-ftp-http-codes branch from cb5c41d to e4a9c71 Compare October 9, 2026 00:59
@JarryShaw
JarryShaw marked this pull request as ready for review October 9, 2026 00:59
@JarryShaw JarryShaw added review: running A cross-review is in flight against the current head - no verdict yet and removed review: pending No verdict for the current head - never reviewed, or the head moved since the last one labels Oct 9, 2026
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Coverage: 89.51% (unit tier, Python 3.14, e4a9c71a4, Unit Tests run success)

Package Statements Missed Branches Partial Cover
pcapkit (top level) 104 4 20 4 93.55%
pcapkit/const 18795 968 2356 869 90.90%
pcapkit/corekit 2043 89 636 25 94.77%
pcapkit/dumpkit 234 2 84 2 98.74%
pcapkit/foundation 2648 98 930 48 94.80%
pcapkit/interface 112 7 40 5 92.11%
pcapkit/protocols 16798 219 4520 183 98.08%
pcapkit/toolkit 539 74 168 3 84.58%
pcapkit/utilities 429 4 122 4 98.55%
pcapkit/vendor 4409 2342 1006 157 43.25%

Per-file detail: the coverage-html artifact of this run.

@JarryShaw

Copy link
Copy Markdown
Owner Author

Verdict: GOOD TO GO at e4a9c71a4 (Sonnet cross-review; the author ran on Opus).

  • Round trips, all 1000 codes. Parse→from_data and make(code=N)→parse are byte-exact for every code 000–999, across FTP single-line, FTP multi-line and HTTP. On main, 440 FTP and 500 HTTP codes fail.
  • No change for codes that worked. Every member, and every code that parsed on main, gives info identical to main (1181 entries). The 237 FTP/HTTP layers in the captures are also unchanged.
  • Pseudo-members are never registered: __members__ stays the same size after 1000 lookups. They pickle, hash equal to the int, and use the name Unknown, which 4 other registries already use.
  • FTP kind/group below 100 follows RFC 959's 3-digit form, and nothing outside the const module reads them.
  • Regeneration. Re-running both crawlers on the saved snapshots gives byte-identical files.
  • Tests, which I re-ran: the new module gives 9 passed and 2017 subtests. With the 4 runtime files from main, it gives 951 failed subtests.
  • Neighbours. The const leg runs 502 tests with 0 failures. tests/project gives 419 passed.

For the owner: ReturnCode(0) and StatusCode(0) used to raise, and #492 recorded that as correct. They now resolve to Unknown, which follows the byte-exact rule. The PR body says so. No ! in my view, but it is your call whether that counts as public contract.

@JarryShaw JarryShaw added review: good-to-go Cross-review at the current head says ready; CI state is separate and removed review: running A cross-review is in flight against the current head - no verdict yet labels Oct 9, 2026
@JarryShaw
JarryShaw merged commit 2174524 into main Oct 9, 2026
41 checks passed
@JarryShaw
JarryShaw deleted the fix/1443-unassigned-ftp-http-codes branch October 9, 2026 02:01
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Oct 9, 2026
@JarryShaw JarryShaw added this to the PyPCAPKit v1.5 milestone Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

const Regenerated IANA or vendor constant tables; members keep their numeric values fix Pull requests that fix a defect (fix: subject prefix)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fix(const): FTP ReturnCode and HTTP StatusCode raise on an unassigned code, so the reply cannot parse

1 participant