Screen PDS endpoint hosts without Network.framework - #55
Merged
Conversation
Network is Apple-only, so ServiceEndpoint.swift kept the package from building on Linux or Android. IPv4Address has no libc equivalent — it accepts 16843009 and 0x7f000001, which inet_pton rejects — so its grammar is reimplemented and pinned against readings taken from the real parser. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 17738ad The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
IPv4Address only reads leading zeros as decimal in dotted quads; shorter forms take inet_aton's octal grammar, so 010 is 0.0.0.8 and 018015111 is no address at all. The decimal-everywhere reimplementation read that last class as public literals, exempting dotless spellings the single-label rule rejects on main. Also fixes the changeset package name. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Merged
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.
ServiceEndpoint.swiftimportedDarwinandNetwork, so the package does notbuild on Linux or Android. This replaces those with libc plus one reimplemented
parser, ahead of adding the Linux and Android CI legs.
Why the parsers couldn't just move to
inet_ptonNetwork'sIPv4Addressis not a strict dotted-quad parser. Readings taken fromit on macOS:
IPv4Addressinet_ptoninet_aton168430090x7f000001127.10177.0.0.1010https://16843009is an accepted endpoint in the existing tests, and it is onlyaccepted because
IPv4Addressvouches for it as a literal —inet_ptonrejectsthe short forms, so swapping it in would have started rejecting valid dotless
literals.
The probes pin down
IPv4Address's actual shape: for a dotted quad it uses apermissive grammar of its own (leading zero decimal,
0xhex); for everythingelse it defers to
inet_aton, octal included —010is 0.0.0.8, and018015111is no address at all (8 is not an octal digit).IPLiteral.v4mirrors exactly that: a reimplementation of the quad grammar, pinned by tests,
and
legacyV4/inet_atonfor every other shape.v6moves toinet_pton(AF_INET6)— byte-identical toIPv6Addresson every case probed,including embedded v4 and
%zonesuffixes — andIPLiteral.embeddedV4reproduces
asIPv4, since the::1distinction is what the loopback exemptionturns on.
Getting the non-quad deferral right matters for the screening, not just
compatibility: a decimal-everywhere reading would have accepted dotless
spellings like
018015111as public literals, exempting them from thesingle-label rule that exists because such names resolve through local search
domains.
https://018015111is now pinned as rejected inPDSEndpointTests.Behavior
Unchanged on Apple platforms — all 33 existing tests pass untouched. The one
probed divergence from
IPv4Addressis a quad part of0xwith no digits(
1.0x.2.3), which read as zero there and has no reading here; it loses theliteral exemption and is screened as a name, and where the platform's
inet_atonreads it, that reading is still screened.IPLiteralTestspins the accepted spellings (quad-decimal and octal-deferralforms), the rejected ones, the leading-zero disagreement between the two v4
readings, and the v4-in-v6 table against readings probed from the real
Networkparsers, so drift in the reimplementation fails a test rather than opening a
hole.
Part of GER-2175.
🤖 Generated with Claude Code