Repository navigation
fix(relay): measure a subscription id in UTF-16 code units, as the capture does - #1400
Conversation
…pture does (cherry picked from commit 0f5a2d8)
🦋 Changeset detectedLatest commit: cbcad87 The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types 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 |
|
No actionable comments were generated in the recent review. Walkthrough
Change: Bug fix · Severity of issue fixed: Medium Merge Risk:
|
Confidence Score: 5/5
[Medium impact] This PR appears safe to merge.
|
What
REQandCOUNTsubscription ids are now measured in UTF-16 code units everywhere, which is what the capture does.The port measured the same id three different ways:
decode_requestcounted Unicode scalars (chars().count()), and both handlers counted UTF-8 bytes (.len()), against the same 256 bound. The capture counts JavaScript stringlength— UTF-16 code units — at all three sites (src/schemas/message-schema.ts:11,:34;src/handlers/subscribe-message-handler.ts:297;src/handlers/count-message-handler.ts:69). So an id of 100 CJK characters (300 bytes) was refused by both handlers although the capture accepts it, and an id of 200 emoji (400 units) passed the decoder although the capture refuses it.Provenance
Cherry-picked with
-xfrom saket0187#9 (0f5a2d8b), which is the fix proposed on #954. Diff read in full before it entered the tree; no workflow, dependency or install-time change. The prose in the commit and the ADR addition screened clear.Verification
cargo test -p nostream-core --test wire_codec: 28 passed.cargo test -p nostream-relay --test handlers: 71 passed.decode_bounds_the_subscription_id_in_utf16_code_unitsred (1 failed) and all three handler tests red (the_subscription_id_limit_counts_utf16_code_units,the_query_id_limit_counts_utf16_code_units,an_id_is_bounded_in_utf16_code_units_at_the_shipped_limit).cargo fmt --checkclean.Kept deliberately the capture's behaviour
The bounds and refusals stay the capture's: 256 UTF-16 units at the frame schema (not NIP-01's 64-character maximum), a
NOTICEonREQand aCLOSEDonCOUNTfor a lower configuredmaxSubscriptionIdLength(not NIP-01/NIP-45'sCLOSED). An id carrying an unpaired surrogate escape is still refused at parse, because a RustStringcannot hold one. ADR 0002 records the unit and the difference; the fuzz target anddocs/rewrite/fuzz.mdnow state the invariant in the same unit.Closes #954
After the merge
rewrite/mainis not the default branch, so GitHub will not close #954 when this lands in it — it gets closed by hand with the merge sha, the same way #1324 was.