René's URL Explorer Experiment


Title: fix: bound TC-deferred queues against spoofed-source flood OOM by bdraco · Pull Request #1751 · python-zeroconf/python-zeroconf · GitHub

Open Graph Title: fix: bound TC-deferred queues against spoofed-source flood OOM by bdraco · Pull Request #1751 · python-zeroconf/python-zeroconf

X Title: fix: bound TC-deferred queues against spoofed-source flood OOM by bdraco · Pull Request #1751 · python-zeroconf/python-zeroconf

Description: Summary AsyncListener.handle_query_or_defer retains every truncated incoming query in self._deferred[addr] and arms a per-addr timer that flushes within ~500ms; neither the per-addr list nor the number of distinct addr keys was capped, so a LAN peer streaming byte-distinct TC-flagged queries; trivially amplified by spoofing source IPs, could grow _deferred and _timers until the process OOMs. This PR adds a per-addr cap, a total-addrs cap, and FIFO eviction so the worst-case memory footprint of the TC-deferral path stays bounded. Details _MAX_DEFERRED_PER_ADDR = 16 (const.py): bounds the per-addr queue. RFC 6762 §18.5 anticipates only a handful of segments per truncated query, and 16 is well above legitimate need; the existing O(N) for incoming in reversed(deferred) dedup scan now runs over a constant-bounded list, so the per-arrival CPU cost is constant. _MAX_DEFERRED_ADDRS = 512 (const.py): bounds the total distinct addrs with in-flight TC-deferral state. The cap leaves headroom for a legitimate burst (a LAN-wide power-resume / boot storm where many devices announce at once) while bounding worst-case memory at ~72 MB even under a spoofed-source flood (512 x 16 x _MAX_MSG_ABSOLUTE). _evict_oldest_deferred (src/zeroconf/_listener.py): when a new addr would push _deferred past the cap, the oldest insertion-order entry is evicted; its timer is cancelled, its deadline is dropped, and its queue is discarded. Eviction is FIFO (oldest by first-seen, via dict insertion order) rather than LRU so an active flooder cannot pin its slots by re-sending into the same addr. Both constants are cdef'd in src/zeroconf/_listener.pxd so len(self._deferred) >= _MAX_DEFERRED_ADDRS and len(deferred) >= _MAX_DEFERRED_PER_ADDR compile to direct C integer compares; verified via cython -a. Test plan New tests in tests/test_core.py: test_tc_bit_per_addr_queue_is_bounded: 20 distinct TC-flagged queries from one addr produce a 16-entry queue and retain the first 16 by insertion order. test_tc_bit_total_addrs_is_bounded: 516 distinct source IPs sending TC packets keep _deferred and _timers at exactly 512 entries; uses patch.object(_listener, "_TC_DELAY_RANDOM_INTERVAL", (60_000, 60_001)) so the reassembly timer cannot fire during the test window (otherwise PyPy / slow runners can drain entries between the last enqueue and the assertion). test_tc_bit_eviction_drops_oldest_addr: filling to capacity then adding one more addr drops the original-oldest from both _deferred and _timers; the new addr is present. REQUIRE_CYTHON=1 poetry install --only=main,dev && poetry run pytest tests/ --no-cov --timeout=60: 381 passed, 3 skipped. SKIP_CYTHON=1 poetry run pytest tests/ --no-cov --timeout=60: 381 passed, 3 skipped. poetry run pre-commit run on touched files: ruff, ruff format, mypy, codespell, flake8, cython-lint all green.

Open Graph Description: Summary AsyncListener.handle_query_or_defer retains every truncated incoming query in self._deferred[addr] and arms a per-addr timer that flushes within ~500ms; neither the per-addr list nor the nu...

X Description: Summary AsyncListener.handle_query_or_defer retains every truncated incoming query in self._deferred[addr] and arms a per-addr timer that flushes within ~500ms; neither the per-addr list nor the nu...

Opengraph URL: https://github.com/python-zeroconf/python-zeroconf/pull/1751

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:ee9aea08-59df-c873-8acc-03fe7c26ce8d
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idBDEC:34D742:259FAF:32D0AC:6B008666
html-safe-nonce723bb9befdc1c81dc743600a819a955074a4a3eca711be6788df15e8d022dd6f
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCREVDOjM0RDc0MjoyNTlGQUY6MzJEMEFDOjZCMDA4NjY2IiwidmlzaXRvcl9pZCI6IjIxODUyNDE1NDA1MTc5ODc5NDIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac39ee345eb93899bc37daa1a38e52d8708fa6a223581f2022ea3699eea273a09d
hovercard-subject-tagpull_request:3717011378
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python-zeroconf/python-zeroconf/pull/1751/files
twitter:imagehttps://avatars.githubusercontent.com/u/663432?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/663432?s=400&v=4
og:image:altSummary AsyncListener.handle_query_or_defer retains every truncated incoming query in self._deferred[addr] and arms a per-addr timer that flushes within ~500ms; neither the per-addr list nor the nu...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None4d3d8e50f02c1d7bf86d5acfa1d3bfe9366abd6528a6b429eb07a168429d2b61
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/python-zeroconf/python-zeroconf git https://github.com/python-zeroconf/python-zeroconf.git
octolytics-dimension-user_id120192235
octolytics-dimension-user_loginpython-zeroconf
octolytics-dimension-repository_id21548731
octolytics-dimension-repository_nwopython-zeroconf/python-zeroconf
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id21548731
octolytics-dimension-repository_network_root_nwopython-zeroconf/python-zeroconf
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasedb758f8e02b8257935fb03edf81a3e76eb3abd11
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python-zeroconf/python-zeroconf/pull/1751/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-zeroconf%2Fpython-zeroconf%2Fpull%2F1751%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-zeroconf%2Fpython-zeroconf%2Fpull%2F1751%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=python-zeroconf%2Fpython-zeroconf
Reloadhttps://github.com/python-zeroconf/python-zeroconf/pull/1751/files
Reloadhttps://github.com/python-zeroconf/python-zeroconf/pull/1751/files
Reloadhttps://github.com/python-zeroconf/python-zeroconf/pull/1751/files
python-zeroconfhttps://github.com/python-zeroconf
python-zeroconfhttps://github.com/python-zeroconf/python-zeroconf
Codehttps://github.com/python-zeroconf/python-zeroconf
Issues50 (50)https://github.com/python-zeroconf/python-zeroconf/issues
Pull requests16 (16)https://github.com/python-zeroconf/python-zeroconf/pulls
Discussionshttps://github.com/python-zeroconf/python-zeroconf/discussions
Actionshttps://github.com/python-zeroconf/python-zeroconf/actions
Projectshttps://github.com/python-zeroconf/python-zeroconf/projects
Wikihttps://github.com/python-zeroconf/python-zeroconf/wiki
Security and quality5 (5)https://github.com/python-zeroconf/python-zeroconf/security
Insightshttps://github.com/python-zeroconf/python-zeroconf/insights
Sign up for GitHub https://github.com/signup?return_to=%2Fpython-zeroconf%2Fpython-zeroconf%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython-zeroconf%2Fpython-zeroconf%2Fissues%2Fnew%2Fchoose
bdracohttps://github.com/bdraco
masterhttps://github.com/python-zeroconf/python-zeroconf/tree/master
fix/bound-tc-deferred-queueshttps://github.com/python-zeroconf/python-zeroconf/tree/fix/bound-tc-deferred-queues
Conversation 12 https://github.com/python-zeroconf/python-zeroconf/pull/1751
Commits 1 https://github.com/python-zeroconf/python-zeroconf/pull/1751/commits
Checks 35 https://github.com/python-zeroconf/python-zeroconf/pull/1751/checks
Files changed https://github.com/python-zeroconf/python-zeroconf/pull/1751/files
Please reload this pagehttps://github.com/python-zeroconf/python-zeroconf/pull/1751/files
fix: bound TC-deferred queues against spoofed-source flood OOM https://github.com/python-zeroconf/python-zeroconf/pull/1751/files#top
Show all changes 1 commit https://github.com/python-zeroconf/python-zeroconf/pull/1751/files
2c927fd fix: bound TC-deferred queues against spoofed-source flood OOM bdraco May 20, 2026 https://github.com/python-zeroconf/python-zeroconf/pull/1751/commits/2c927fd287c5ffae9a66b585d38678eac84cbf3c
Clear filters https://github.com/python-zeroconf/python-zeroconf/pull/1751/files
Please reload this pagehttps://github.com/python-zeroconf/python-zeroconf/pull/1751/files
Please reload this pagehttps://github.com/python-zeroconf/python-zeroconf/pull/1751/files
_listener.pxd https://github.com/python-zeroconf/python-zeroconf/pull/1751/files#diff-bff2b43c81cd5dc78e524ed6cd0a7c8cef9ad4cd2410097ad3b4cd20f73f589a
_listener.py https://github.com/python-zeroconf/python-zeroconf/pull/1751/files#diff-482d92e649d0a9dfb6f7434c0ec1854490aeda07f86f21ac36e348a9ad1ab4d2
const.py https://github.com/python-zeroconf/python-zeroconf/pull/1751/files#diff-2925fab357e035f1e0cb51ebce6d44e682392bccd5b6b5809dc1f5ea78d6d9b4
test_core.py https://github.com/python-zeroconf/python-zeroconf/pull/1751/files#diff-938de46e643ab091cff6a7c23e4e752e8907e2266f47889d988923352f7a1058
src/zeroconf/_listener.pxdhttps://github.com/python-zeroconf/python-zeroconf/pull/1751/files#diff-bff2b43c81cd5dc78e524ed6cd0a7c8cef9ad4cd2410097ad3b4cd20f73f589a
View file https://github.com/python-zeroconf/python-zeroconf/blob/2c927fd287c5ffae9a66b585d38678eac84cbf3c/src/zeroconf/_listener.pxd
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python-zeroconf/python-zeroconf/pull/1751/{{ revealButtonHref }}
https://github.com/python-zeroconf/python-zeroconf/pull/1751/files#diff-bff2b43c81cd5dc78e524ed6cd0a7c8cef9ad4cd2410097ad3b4cd20f73f589a
https://github.com/python-zeroconf/python-zeroconf/pull/1751/files#diff-bff2b43c81cd5dc78e524ed6cd0a7c8cef9ad4cd2410097ad3b4cd20f73f589a
https://github.com/python-zeroconf/python-zeroconf/pull/1751/files#diff-bff2b43c81cd5dc78e524ed6cd0a7c8cef9ad4cd2410097ad3b4cd20f73f589a
src/zeroconf/_listener.pyhttps://github.com/python-zeroconf/python-zeroconf/pull/1751/files#diff-482d92e649d0a9dfb6f7434c0ec1854490aeda07f86f21ac36e348a9ad1ab4d2
View file https://github.com/python-zeroconf/python-zeroconf/blob/2c927fd287c5ffae9a66b585d38678eac84cbf3c/src/zeroconf/_listener.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python-zeroconf/python-zeroconf/pull/1751/{{ revealButtonHref }}
https://github.com/python-zeroconf/python-zeroconf/pull/1751/files#diff-482d92e649d0a9dfb6f7434c0ec1854490aeda07f86f21ac36e348a9ad1ab4d2
https://github.com/python-zeroconf/python-zeroconf/pull/1751/files#diff-482d92e649d0a9dfb6f7434c0ec1854490aeda07f86f21ac36e348a9ad1ab4d2
https://github.com/python-zeroconf/python-zeroconf/pull/1751/files#diff-482d92e649d0a9dfb6f7434c0ec1854490aeda07f86f21ac36e348a9ad1ab4d2
https://github.com/python-zeroconf/python-zeroconf/pull/1751/files#diff-482d92e649d0a9dfb6f7434c0ec1854490aeda07f86f21ac36e348a9ad1ab4d2
https://github.com/python-zeroconf/python-zeroconf/pull/1751/files#diff-482d92e649d0a9dfb6f7434c0ec1854490aeda07f86f21ac36e348a9ad1ab4d2
https://github.com/python-zeroconf/python-zeroconf/pull/1751/files#diff-482d92e649d0a9dfb6f7434c0ec1854490aeda07f86f21ac36e348a9ad1ab4d2
src/zeroconf/const.pyhttps://github.com/python-zeroconf/python-zeroconf/pull/1751/files#diff-2925fab357e035f1e0cb51ebce6d44e682392bccd5b6b5809dc1f5ea78d6d9b4
View file https://github.com/python-zeroconf/python-zeroconf/blob/2c927fd287c5ffae9a66b585d38678eac84cbf3c/src/zeroconf/const.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python-zeroconf/python-zeroconf/pull/1751/{{ revealButtonHref }}
https://github.com/python-zeroconf/python-zeroconf/pull/1751/files#diff-2925fab357e035f1e0cb51ebce6d44e682392bccd5b6b5809dc1f5ea78d6d9b4
Please reload this pagehttps://github.com/python-zeroconf/python-zeroconf/pull/1751/files
https://github.com/python-zeroconf/python-zeroconf/pull/1751/files#diff-2925fab357e035f1e0cb51ebce6d44e682392bccd5b6b5809dc1f5ea78d6d9b4
tests/test_core.pyhttps://github.com/python-zeroconf/python-zeroconf/pull/1751/files#diff-938de46e643ab091cff6a7c23e4e752e8907e2266f47889d988923352f7a1058
View file https://github.com/python-zeroconf/python-zeroconf/blob/2c927fd287c5ffae9a66b585d38678eac84cbf3c/tests/test_core.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python-zeroconf/python-zeroconf/pull/1751/{{ revealButtonHref }}
https://github.com/python-zeroconf/python-zeroconf/pull/1751/files#diff-938de46e643ab091cff6a7c23e4e752e8907e2266f47889d988923352f7a1058
https://github.com/python-zeroconf/python-zeroconf/pull/1751/files#diff-938de46e643ab091cff6a7c23e4e752e8907e2266f47889d988923352f7a1058
https://github.com/python-zeroconf/python-zeroconf/pull/1751/files#diff-938de46e643ab091cff6a7c23e4e752e8907e2266f47889d988923352f7a1058
Please reload this pagehttps://github.com/python-zeroconf/python-zeroconf/pull/1751/files
https://github.com/python-zeroconf/python-zeroconf/pull/1751/files#diff-938de46e643ab091cff6a7c23e4e752e8907e2266f47889d988923352f7a1058
Please reload this pagehttps://github.com/python-zeroconf/python-zeroconf/pull/1751/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.