add frame decoder recovery tests and fix header size mismatch#8
Open
bilalabsh wants to merge 1 commit into
Open
add frame decoder recovery tests and fix header size mismatch#8bilalabsh wants to merge 1 commit into
bilalabsh wants to merge 1 commit into
Conversation
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
Closes #2
The frame codec had basic encode/decode tests, but nothing covered malformed wire input or whether the decoder recovers cleanly after a bad frame. The header was also wrong — encoder wrote 20 bytes of header while FRAME_HEADER_SIZE is 24, so round-trip decode was already broken on main.
This PR fixes that header mismatch, adds reserved-byte validation and an accepted_frames counter on FrameDecoder, and adds deterministic regression tests for truncated input, integrity failures, and post-failure recovery. No live services involved.
What Changed
backend/src/protocol/codec.rs
Fixes header encoding/decoding: reserved field is 8 bytes (was 4), matching FRAME_HEADER_SIZE = 24.
Rejects non-zero reserved bytes with ProtocolError::InvalidMessage and drains the bad frame from the buffer.
Adds accepted_frames counter and accepted_frames() getter on FrameDecoder, incremented only on successful decode.
backend/src/protocol/frame_tests.rs
New test module with helpers for building valid/malformed frame fixtures.
8 tests covering:
Truncated header → Ok(None), no panic
Truncated payload → Ok(None), no panic
Oversize payload length → MessageTooLarge
Non-zero reserved bytes → InvalidMessage
Checksum corruption → ChecksumMismatch
Failed decode leaves accepted_frames at 0 and buffer in a sane state
Valid frame decodes successfully after checksum failure
Valid frame decodes successfully after invalid reserved bytes
backend/src/protocol/mod.rs
Wires in frame_tests under #[cfg(test)].
diagnostic/
Ran python3 build.py on this branch.
How I Tested
cd backend
cargo test --lib protocol::frame_tests
cargo test --lib protocol::codec::tests
cargo test --lib
8/8 new frame tests passing
4/4 existing codec tests passing
24/24 full lib suite passing