Skip to content

length validation in KeyValuePair::encode for BytesValue #128

@diegocatalao

Description

@diegocatalao

Hello folks,

while writing unit tests for the coding 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

#[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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions