Skip to content

test(websocket): fuzz the topic engine + differential-test the matcher (#2) - #129

Merged
EdmondDantes merged 1 commit into
2-ws-cross-worker-roomsfrom
2-ws-topics-fuzz-oracle-tests
Jul 14, 2026
Merged

EdmondDantes merged 1 commit into
2-ws-cross-worker-roomsfrom
2-ws-topics-fuzz-oracle-tests

Conversation

@EdmondDantes

Copy link
Copy Markdown
Contributor

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.c

Drives ws_topic_tree.c end to end: the MQTT filter parser
(ws_topic_split / ws_topic_is_valid_*), the interest-prefix builder that
feeds the cross-worker filter (ws_topic_prefixes / _interest_prefix), and
the 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.

  • Just the one TU under test — the hub-interest and delivery calls are stubbed
    in the harness, so no threads / mailbox (the tree is per-worker by design).
  • 365,915 runs at ~14k exec/s, 0 crashes under ASAN+UBSan.
  • Ships a seed corpus (wildcards, empty levels, depth 130, #-mid-filter) and
    a dictionary.

2. Differential matcher test — tests/phpt/websocket/055-topics-matching-oracle.phpt

041 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 runs
the same ws_topic_match walk as publish() (delivery off) — a faithful and
synchronous proxy, so no timing flakes. Reaches cases 041 doesn't: +
matching an empty level (a//b), # matching the parent, trailing slash as a
real empty level.

Result: 144 pairs checked, 0 mismatches.

Drive-by fix

A leak-clean run of the new target surfaced a one-time zend_string leak in
the shared fuzz harness (harness_common.c): the "memory_limit" name handed
to zend_alter_ini_entry_chars was never released. It leaked on every
embedded fuzzer's init; now released.

Testing

  • Full tests/phpt/websocket/ suite: 58/58 pass (existing 038–054 topic
    suite + new 055), no regressions.
  • fuzz_ws_topic: builds, corpus replays clean, 365k-run burst clean under
    ASAN+UBSan.
  • -runs=0 on both fuzz_ws_topic and fuzz_ws_frame: leak-clean after the
    harness fix.

No production code changed — tests and fuzz tooling only.

#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.
@EdmondDantes
EdmondDantes merged commit 21c527b into 2-ws-cross-worker-rooms Jul 14, 2026
5 checks passed
@EdmondDantes
EdmondDantes deleted the 2-ws-topics-fuzz-oracle-tests branch July 14, 2026 12:43
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.

1 participant