Repository navigation
Gate stream/start's sections before parsing them - #242
Merged
Merged
Conversation
stream/start parsed every section, including the player codec_header copy and the visualizer types vector, for every connection before any role gate, so a never-admitted peer could make the protocol task allocate up to 16 KiB through an aborting operator new. Its siblings (server/state, server/command, group/update) gate first. - The dispatch decides each role gate first and passes the taken set to process_stream_start_message(), which parses only those sections. - The player and visualizer sections are moved into their roles, and GenerationSlot::write() takes T&& like merge(). - One rule for a malformed section: it rejects the whole message. The visualizer section now follows it, and a missing types, rate_max or (with beat) tracks_downbeats rejects too, per roles/visualizer/v1.md "stream/start visualizer object". - Allocation windows pin the move and the gate; the protocol task stack figures are re-derived (default unchanged at 7,168).
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Missing or malformed artwork channels and non-string types entries fail to reject the message, allowing neighboring player sections to start in violation of the fail-closed contract.
3 open issues
What changed in this PR
Moves stream/start role checks ahead of section parsing to avoid unnecessary heap allocations from connections that do not own those roles.
Changes:
- Parses only the player, artwork, and visualizer sections accepted by their role gates.
- Moves player and visualizer payloads rather than copying them.
- Tightens visualizer validation and expands regression tests, allocation checks, and resource documentation.
| File | Description |
|---|---|
| tools/stack_usage/README.md | Updates protocol-task stack bounds and sizing rationale. |
| tests/test_visualizer_role.cpp | Adapts tests to moved configurations and updates parser comments. |
| tests/test_protocol.cpp | Adds role-selection and visualizer-validation cases. |
| tests/test_player_role.cpp | Passes stream parameters by move. |
| tests/test_json_arena.cpp | Uses role-aware stream extraction. |
| tests/test_client_lifecycle.cpp | Adapts lifecycle tests to consuming stream handlers. |
| tests/test_allocations.cpp | Checks skipped-section allocations and visualizer payload moves. |
| tests/README.md | Documents expanded allocation coverage. |
| src/visualizer_role.cpp | Moves stream configuration into the generation slot. |
| src/visualizer_role_impl.h | Updates the stream-handler signature. |
| src/protocol.cpp | Adds role-selected section parsing and stricter visualizer validation. |
| src/protocol_messages.h | Documents the role-aware parser contract. |
| src/player_role.cpp | Accepts stream parameters by rvalue reference. |
| src/player_role_impl.h | Updates the player handler declaration. |
| src/inbox.h | Makes generation-slot writes accept rvalue references. |
| src/client_dispatch.cpp | Applies role gates before parsing and moves accepted payloads. |
| docs/internals.md | Updates message-field allocation behavior. |
| CLAUDE.md | Documents additional allocation-test scenarios. |
Review effort: Max
…r type - An artwork stream/start object without a channels array rejects the message, per roles/artwork/v1.md "stream/start artwork object"; it was treated as absent. - A visualizer types entry that is not a string rejects the message; an unrecognized type string is still skipped. - The role-deactivation test comment says removed-role traffic is skipped unparsed.
7 tasks done
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.


Summary
From the second coherence pass on the allocation follow-ups (Sendspin/backlog#92).
stream/startparsed every section, including the playercodec_headercopy and the visualizertypesvector, for every connection before any role gate. So a never-admitted peer (one keyed with the published Sentinel PSK) could make the protocol task allocate up to 16 KiB, and an admitted non-owner up to 1 MiB, through ESPHome's abortingoperator new. Its siblingsserver/state,server/commandandgroup/updatealready gate first. The order dates from the initial commit; it is not a regression from the allocation series.Change
EnumSet<SendspinRole>) toprocess_stream_start_message(). It parses only those sections; an untaken section is skipped unvalidated, as inserver/state.GenerationSlot::write()takesT&&likemerge().typesorrate_max, or a missingtracks_downbeatswhen beat is listed, rejects too, per roles/visualizer/v1.md "stream/start visualizer object".role_accepts_traffic()'s doc,internals.md"Memory", thesendspin_alloc_testssentence in CLAUDE.md and tests/README.md, andtools/stack_usage/README.md, re-derived: the protocol task's -Og bound goes 6,672 -> 6,688, and itsstream/startchain 6,352 -> 5,296, so the deepest reachable chain is pairing confirm at 6,144. The 7,168 default is unchanged and covers the full -Og bound plus margin.Tests
sendspin_alloc_tests: a FLACstream/startwith a longcodec_headerwhile the player role is not taken allocates 0; parsing before the gate makes it 1. Thestream/*window adds an artwork + visualizerstream/startat 1 allocation (the parse'stypesvector); copying into the visualizer slot makes it 2.Protocol.StreamStartParsesOnlyTheTakenSections: a parser that ignores the role set fails it.Protocol.StreamStartRejectsSpectrumWithoutValidConfigandProtocol.StreamStartRejectsAnIncompleteVisualizerSection: a table with controls, each row also checking that the valid player section beside it is reset; dropping any of the checks fails its row.