Repository navigation
fix(corekit): range-check ports in PortEnumField, and document NumberField's masking (#2314) - #2335
Merged
Merged
Conversation
Owner
Author
|
Review: GOOD TO GO at
|
…Field's masking (#2314) Problem: a TCP or UDP schema built directly packed an out-of-range port by masking it to 16 bits (srcport=70000 -> 0x1170, -1 -> 0xffff), because PortEnumField.pre_process handed a bare int to NumberField's mask unchecked. Fix: the UDP, TCP and SCTP port fields already use PortEnumField (#1516, #1526), so the fix is the range check there: its pre_process raises FieldValueError for a port outside the field's width. NumberField keeps masking as the documented schema contract (#1488); the NumberField and Schema docstrings say direct construction does not range-check and name where the checks live. Test: test_tcp_udp_schema_port_range_unit.py rejects -1/65536/70000 on both ports of both schemas, and round-trips ports 0 and 65535 byte-exact.
JarryShaw
force-pushed
the
fix/2314-port-field-range
branch
from
October 26, 2026 22:32
ec62c58 to
841014d
Compare
Owner
Author
|
Rebased The old head's |
Contributor
|
Coverage: 91.56% (unit tier, Python 3.15,
Per-file detail: the |
This was referenced Oct 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
make testpasses, and a test case covers the changeWhat is the purpose of your pull request?
fix — bug fixDescription
Closes #2314, per the ruling (take the recommendation, with the ports on the port enum field).
PortEnumField.pre_processraisesFieldValueErrorfor a port outside the field's width. Before, a directly built TCP or UDP schema maskedsrcport=70000to0x1170and-1to0xffff. UDP, TCP and SCTP already usePortEnumField(refactor(corekit): move stream proxy classes such as _PeekableStream into corekit.io #1516, refactor(corekit): share one PortEnumField across TCP, UDP and SCTP (#1516) #1526).NumberFieldkeeps masking, which is its documented contract (fix(corekit): a NumberField whose bit_length is narrower than its octets drops the high bits #1488). TheNumberFieldandSchemadocstrings now say that direct construction does not range-check, and name where the checks live.test_tcp_udp_schema_port_range_unit.pyrejects -1, 65536 and 70000 on both ports of both schemas, and round-trips ports 0 and 65535 byte-exact.origin/main, 12 failed (AssertionError: FieldValueError not raised). On the head, 2 passed with 20 subtests.