Skip to content

Fix IPv6 prefix masks in network and containment functions - #171

Merged
nalgeon merged 1 commit into
nalgeon:mainfrom
ac1982:fix/ipv6-prefix-masks
Oct 14, 2026
Merged

nalgeon merged 1 commit into
nalgeon:mainfrom
ac1982:fix/ipv6-prefix-masks

Conversation

@ac1982

@ac1982 ac1982 commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

ipnetwork() retains host bits in IPv6 addresses because the boundary-byte mask complements the prefix remainder instead of preserving its high bits. For example, the address from #170 with /64 produces 2001:db8:1111:2222:3300::/64 instead of 2001:db8:1111:2222::/64.

Apply the correct mask in both ipnetwork() and ipcontains(), which uses the same calculation on its two operands. Includes SQL regressions for byte boundaries, every partial-byte mask, /0, /128, and subnet containment. Fixes #170.

Validation on Linux ARM64:

  • 48 ipaddr SQL checks pass; 14 new cases fail before the fix.
  • 19,284 comparisons against Python ipaddress pass for both standalone and bundled extensions, covering all IPv6/IPv4 prefix lengths.
  • Linux build, C tests and all 14 SQL suites pass with the file permissions expected by the fileio tests. The ambient umask causes the same two fileio failures on the base.
  • Address/undefined-behavior sanitizer checks pass (leak detection disabled); the full comparison also passes under UBSan.

Windows and macOS were not tested locally. Developed and tested with OpenAI Codex.

@nalgeon
nalgeon merged commit 8ae3f7c into nalgeon:main Oct 14, 2026
3 checks passed
@nalgeon

nalgeon commented Oct 14, 2026

Copy link
Copy Markdown
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wrong IPv6 network calculation

2 participants