Repository navigation
Cap server-sent friendly names in UTF-8 bytes - #339
Merged
Merged
Conversation
kahrendt
added a commit
to Sendspin/sendspin-cpp
that referenced
this pull request
Nov 3, 2026
## Summary Removes the server-identity heap allocations between accept and admission. The connection kept the server's id and name as a `ServerInformationObject` (two `std::string`s), and the published slot copied it. A 43-character id is too long for either standard library's inline string storage, and under libstdc++ so is a name over 15 characters. Admission made 3 such allocations on libc++ and 5 on libstdc++ (ESP-IDF); it now makes 1 on both. Depends on Sendspin/spec#339, which caps `server/hello`'s `name` and `group/update`'s `group_name` at 64 bytes in UTF-8. ## Change - `InlineText<N>` (`src/inline_text.h`) holds bounded text inside the object; `IdText` is now `InlineText<PEER_ID_SIZE>`. `utf8_truncate()` cuts text at a character boundary. - The connection holds the server id as an `IdText` and the name as a 64-byte `ServerName`. `get_server_id()` returns `const IdText&`, and the helpers that took the id as a `std::string` take a `std::string_view`. - The published slot holds the same inline copies. `get_server_information()` builds the public `ServerInformationObject` on the caller's thread, so the public API is unchanged. - `read_friendly_name()` truncates `server/hello`'s `name` and `group/update`'s `group_name` to 64 bytes with one warning log. `group_name` stays a `std::string` in the public `GroupUpdateObject`. - `tools/stack_usage/README.md` is re-derived from fresh ESP32 builds: - protocol task bound at -Og: 6,656 → 6,704 (`ServerHelloMessage` now holds the name inline); - reachable figure at -Og: 6,400 → 6,368; - the 7,168 default does not change. ## Tests - `test_inline_text.cpp`: a table of truncation cases (at the cap, before a lead byte, inside 2-, 3- and 4-byte characters, malformed continuation runs, only continuation bytes before the cut), plus `InlineText::assign()` refusing text over its capacity. - `Protocol.FriendlyNamesAreTruncatedToTheirCap`: a name at the cap is kept whole, and one with a character straddling the cap is truncated before it, for both fields. - `JunkProbeDoesNotBlockRealServer` now also checks the published name through `get_server_information()`. No test checked it before, so a mutant that dropped it passed. - `ADMISSION_ALLOCATIONS` is lowered to 1, checked under clang / libc++ and GCC 16 / libstdc++. The one left is the trust-change note `on_handshake_complete()` queues. - Mutants killed: no truncation in `read_friendly_name()`, unbounded back-off, the `len > 0` guard removed (ASan out-of-bounds read), and the published name dropped.
maximmaxim345
approved these changes
Nov 3, 2026
maximmaxim345
left a comment
Member
There was a problem hiding this comment.
Nice catch, missed them. Thanks @kahrendt!
1 task done
kahrendt
pushed a commit
that referenced
this pull request
Nov 5, 2026
<!-- Describe the change and why it is needed. --> A recognized message can carry a value outside its field's fixed range, such as `output_delay_ms` above 5000 in `client/state` or a controller `volume` of 101. Most fields don't say what the receiver does with one. This makes such a value a protocol error, and the receiver MUST close the connection. Only a broken implementation sends one, and closing matches how the spec treats other protocol errors. The rule only covers fixed ranges and length limits. Bounds relative to another value, like the visualizer `rate_max` or the player timing bounds, can be crossed by a message in flight, and the receiver often can't check them reliably. A field or message with its own rule keeps it: the server still ignores a `seek` outside 0 to `seek_max_ms`, a bad `client/init` is still an init failure, and the #344 `client/hello` caps keep their MAY close. This also removes handling the rule now covers: - truncating an over-long server `name` or `group_name` (from #339) and `client/pair-pending` `message` (from #194) - the SHOULD close for an artwork `channels` array longer than 4 - the player clamp rules for `output_delay_ms` and `min_buffer_ms`, since their 0-5000 field ranges already bind the sender It also adjusts text the rule would otherwise break: - an artwork client that truncates its `channels` array keeps at least one entry - metadata `track` states its range (at least 1), and `year` no longer says "YYYY format" - values inside ignored inactive-role objects are left unvalidated - sending a value outside a range or length limit an earlier revision defined needs negotiation, like a new field So plain text over its byte cap now closes the connection too, including a client `name` or `device_info` string over 64 bytes. - [x] I accept the [Contributor License Agreement](../blob/main/CONTRIBUTOR-LICENSE-AGREEMENT.md) for this contribution.
1 of 9 tasks
maximmaxim345
added a commit
to Sendspin/aiosendspin
that referenced
this pull request
Nov 17, 2026
# What does this implement/fix? <!-- Quick description and explanation of changes. --> Clients that follow the spec close the connection when the server/hello `name` or the group/update `group_name` is longer than 64 bytes in UTF-8. A long or non-Latin server name therefore made them reconnect in a loop. The server now cuts both names to 64 bytes without splitting a character. It cuts the mDNS `name` the same way. `SendspinServer.name` and `SendspinGroup.group_name` still return the full name. **Related issue or spec PR (if applicable):** - Sendspin/spec#339 - Sendspin/spec#347 ## Types of changes <!-- Tick exactly one box. CI (.github/workflows/pr-labels.yaml) applies the matching label, and the release notes use it to sort this change. --> - [x] Bugfix (non-breaking change which fixes an issue): `bugfix` - [ ] New feature (non-breaking change which adds functionality): `new-feature` - [ ] Enhancement to an existing feature: `enhancement` - [ ] Breaking change (changes the public API or the protocol in a way that is not backwards compatible): `breaking-change` - [ ] Refactor (no behavior change): `refactor` - [ ] Documentation only: `documentation` - [ ] Maintenance / chore: `maintenance` - [ ] CI / workflow change: `ci` - [ ] Dependencies bump: `dependencies`
53 of 58 tasks
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.
#329 capped the text fields a client sends in
client/hello. The server sends two friendly names that the client stores and shows:nameinserver/helloandgroup_nameingroup/update. Neither has a length limit.This caps both at 64 bytes in UTF-8, so a client can hold them in fixed storage instead of an allocation whose size the server controls. 64 bytes matches the client-side caps from #329, which follow Matter's 64-byte version strings and UPnP's friendly-name guidance. The cap counts bytes, not characters, so both sides count the same way.
A client that receives a longer value truncates it at a UTF-8 character boundary instead of closing the connection. The server would send the same name again on every reconnect, so closing would leave the client disconnecting over and over, with nothing to show the user that a name is the cause. A
group_namethe server didn't check would disconnect every client in the group. This matches theclient/pair-pendingmessage, the one other display string with a cap, where the receiver truncates.The server's mDNS TXT
nameis not capped, matching #329's handling of the client's TXTname. It SHOULD match theserver/hellonameand is only a discovery hint.