Repository navigation
Allow receivers to limit fragmented message and artwork sizes - #322
Merged
Merged
Conversation
kahrendt
approved these changes
Oct 21, 2026
kahrendt
left a comment
Contributor
There was a problem hiding this comment.
This is a good change for embedded!
11 of 12 tasks
1 task done
kahrendt
pushed a commit
that referenced
this pull request
Nov 4, 2026
<!-- Describe the change and why it is needed. --> `client/hello` is the only message whose content a server can't know in advance. It can carry support objects for application-specific roles, and it arrives before any role is negotiated, so a server that doesn't implement such a role still has to parse its object. A server that parses JSON with a fixed nesting limit closes the connection on a deeply nested object, even though unknown fields must be ignored. No server can meet the "large enough that no valid message it can receive exceeds it" from #322 for `client/hello` either, since it has no maximum size. When the server initiated the connection and playback is running, it reconnects after a drop, so an oversized hello turns into a reconnect loop. A `client/hello` now has at most 10 nesting levels and 16384 bytes, and servers must accept anything within those limits: - 10 levels, counting the root object as level 1. The deepest `client/hello` today is 5 levels, for example `player@v1_support.supported_formats`. 10 is also ArduinoJson's default limit, and it counts levels the same way. - 16384 bytes. A `client/hello` with every field at its maximum length and 82 formats is 6257 bytes. The formats cover 8 sample rates from 44.1 to 384 kHz, mono and stereo, every PCM and FLAC bit depth, and Opus. Only listing every channel count from 1 to 8 goes over, at 22223 bytes. A player over the cap drops its lowest priority formats. I first looked at size caps for every JSON message and length caps for the metadata strings. I left them out, since every other message is either defined by the spec or only sent for roles both sides implement, so the spec already controls how large and how deep it gets. `server/hello` can't carry application-specific support objects, so it needs no cap. sendspin-server-cpp already accepts both limits. - [x] I accept the [Contributor License Agreement](../blob/main/CONTRIBUTOR-LICENSE-AGREEMENT.md) for this contribution.
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.
The fragmentation rules had no size limit, so a peer could send a first fragment followed by non-last fragments forever and grow the receiver's reassembly buffer without bound.
Receivers may now close the connection once the reassembled data passes a limit they choose. I didn't pick a fixed number since the spec doesn't bound sample rate, channels or bit depth. A 150 ms PCM chunk at 384 kHz, 8 channels and 24-bit is already about 1.38 MB, and a fixed cap large enough for that wouldn't protect small devices. Each receiver knows what it can receive, so it can pick its own.
Artwork had the same gap, since
total_sizeis a uint32 and the per-message cap says nothing about the whole image. Clients may now discard an image above a limit they choose. I went with discarding instead of closing, so playback keeps running and a resent image can't cause a reconnect loop.The limits say "valid message" and "valid image" instead of "from a well-behaved client or server", since "valid" is what the rest of the spec already uses.