Repository navigation
test(websocket): fuzz the topic engine + differential-test the matcher (#2) - #129
Merged
EdmondDantes merged 1 commit intoJul 14, 2026
Merged
Conversation
#2) Covers the untrusted-input surface of the cross-worker topic feature — topic names and subscribe filters arrive verbatim from the network. - fuzz/fuzz_ws_topic.c: a libFuzzer target for ws_topic_tree.c (the MQTT filter parser, the interest-prefix builder, and the wildcard matcher + node lifecycle). This TU was previously weak-stubbed out of the frame fuzzer, so the parser/matcher had no fuzz coverage. 365k runs clean under ASAN+UBSan. - tests/phpt/websocket/055-topics-matching-oracle.phpt: a differential test of the C matcher against a PHP MQTT reference oracle over a full filter x topic matrix, driven through subscriberCount() (same tree walk as publish, but synchronous, so no timing flakes). Also releases a one-time zend_string leak in the shared fuzz harness that a leak-clean run of the new target surfaced (harness_common.c) — it had been leaking on every embedded fuzzer's init.
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.
What
Adds test coverage for the untrusted-input surface of the cross-worker
WebSocket topic feature (#2). Topic names and subscribe filters arrive
verbatim from the network, so the MQTT filter parser and the wildcard matcher
are attacker-reachable and deserve dedicated coverage.
1. libFuzzer target for the topic engine —
fuzz/fuzz_ws_topic.cDrives
ws_topic_tree.cend to end: the MQTT filter parser(
ws_topic_split/ws_topic_is_valid_*), the interest-prefix builder thatfeeds the cross-worker filter (
ws_topic_prefixes/_interest_prefix), andthe wildcard matcher + node lifecycle (subscribe / unsubscribe / tombstone
compaction / empty-node prune / recursive walk). This TU was previously
weak-stubbed out of the frame fuzzer, so it had no fuzz coverage.
in the harness, so no threads / mailbox (the tree is per-worker by design).
#-mid-filter) anda dictionary.
2. Differential matcher test —
tests/phpt/websocket/055-topics-matching-oracle.phpt041 pins a handful of wildcard cases by hand; this checks the C matcher against
a small, obviously-correct PHP MQTT reference oracle across a full
12x12 filter x topic matrix. Driven through
subscriberCount(), which runsthe same
ws_topic_matchwalk aspublish()(delivery off) — a faithful andsynchronous proxy, so no timing flakes. Reaches cases 041 doesn't:
+matching an empty level (
a//b),#matching the parent, trailing slash as areal empty level.
Result:
144 pairs checked, 0 mismatches.Drive-by fix
A leak-clean run of the new target surfaced a one-time
zend_stringleak inthe shared fuzz harness (
harness_common.c): the"memory_limit"name handedto
zend_alter_ini_entry_charswas never released. It leaked on everyembedded fuzzer's init; now released.
Testing
tests/phpt/websocket/suite: 58/58 pass (existing 038–054 topicsuite + new 055), no regressions.
fuzz_ws_topic: builds, corpus replays clean, 365k-run burst clean underASAN+UBSan.
-runs=0on bothfuzz_ws_topicandfuzz_ws_frame: leak-clean after theharness fix.
No production code changed — tests and fuzz tooling only.