cloudflare / cloudflare/moq-rs

length validation in KeyValuePair::encode for BytesValue

Open
#128 3 comments 1 reaction 0 assignees View on GitHub
Dominant language
Rust
Stars
166
Forks
59
Avg merge
18h 21m
Merged PRs (30d)
22

Description

Hello folks,

while writing unit tests for the [coding](https://github.com/cloudflare/moq-rs/blob/f1b1d8bb8266ab9ff12db9d3bea3c7a962aa97b3/moq-transport/src/coding/kvp.rs#L85) module, i noticed decode validates `BytesValue` length against `u16::MAX` (Section 1.4.2), but encode doesn't. i'm not entirely sure if i'm right here (rust isnt my strongest area) but i can open a pr if you think it makes sense.

you can reproduce with this test

```rust
#[test]
fn encode_bytes_length_exceeded() {
let mut buf = BytesMut::new();

// you can just create a vector with 65535 + 1 bytes
// ignoring draft-ietf-moq-transport-15 specification:
//
// "Length: Only present when Type is odd. Specifies the length of
// the Value field in bytes. The maximum length of a value is 2^16-1
// bytes. If an endpoint receives a length larger than the maximum,
// it MUST close the session with a Protocol Violation."
let huge_bytes = vec![0u8; u16::MAX as usize + 1];
let kvp = KeyValuePair::new_bytes(1, huge_bytes);
let result = kvp.encode(&mut buf);

assert!(result.is_err(), "must rejected because bytes > 65535");
}
```

best

Contributor guide

Open the contributing guide

Research direction

Start in moq-transport/src/coding/kvp.rs, focusing on KeyValuePair::encode and the existing BytesValue length check in decode. Run the supplied encode_bytes_length_exceeded reproduction with a 65536-byte value. Done means encoding an oversized BytesValue returns an error and the unit test passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
networking
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.