Skip to content

add frame decoder recovery tests and fix header size mismatch#8

Open
bilalabsh wants to merge 1 commit into
Peter7896:mainfrom
bilalabsh:bilalabsh/rust-protocol-frame-decode-tests
Open

add frame decoder recovery tests and fix header size mismatch#8
bilalabsh wants to merge 1 commit into
Peter7896:mainfrom
bilalabsh:bilalabsh/rust-protocol-frame-decode-tests

Conversation

@bilalabsh

Copy link
Copy Markdown

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[$50 BOUNTY] [Rust] Add protocol frame codec recovery tests

1 participant