Skip to content

Commit

Permalink
Add more buffer length checks
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Feb 1, 2024
1 parent 62e259a commit 49a3fad
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changes

## [codec-0.9.2] - 2024-02-01

* Add more buffer length checks

## [1.0.2] - 2024-01-19

* SenderLink close notification
Expand Down
4 changes: 2 additions & 2 deletions codec/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "ntex-amqp-codec"
version = "0.9.1"
version = "0.9.2"
description = "AMQP 1.0 Protocol Codec"
authors = ["Nikolay Kim <[email protected]>", "Max Gortman <[email protected]>", "Mike Yagley <[email protected]>"]
license = "MIT/Apache-2.0"
edition = "2018"

[dependencies]
ntex-bytes = "0.1.21"
ntex-bytes = "0.1.24"
ntex-codec = "0.6.2"
byteorder = "1.5"
fxhash = "0.2.1"
Expand Down
4 changes: 4 additions & 0 deletions codec/src/codec/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ impl<K: Decode + Eq + Hash, V: Decode, S: BuildHasher + Default> DecodeFormatted
{
fn decode_with_format(input: &mut Bytes, fmt: u8) -> Result<Self, AmqpParseError> {
let header = decode_map_header(input, fmt)?;
decode_check_len!(input, header.size as usize);
let mut map_input = input.split_to(header.size as usize);
let count = header.count / 2;
let mut map: collections::HashMap<K, V, S> =
Expand All @@ -267,6 +268,7 @@ impl<K: Decode + Eq + Hash, V: Decode, S: BuildHasher + Default> DecodeFormatted
impl<T: DecodeFormatted> DecodeFormatted for Vec<T> {
fn decode_with_format(input: &mut Bytes, fmt: u8) -> Result<Self, AmqpParseError> {
let header = decode_array_header(input, fmt)?;
decode_check_len!(input, 1);
let item_fmt = input[0]; // todo: support descriptor
input.split_to(1);
let mut result: Vec<T> = Vec::with_capacity(header.count as usize);
Expand All @@ -281,6 +283,7 @@ impl<T: DecodeFormatted> DecodeFormatted for Vec<T> {
impl DecodeFormatted for VecSymbolMap {
fn decode_with_format(input: &mut Bytes, fmt: u8) -> Result<Self, AmqpParseError> {
let header = decode_map_header(input, fmt)?;
decode_check_len!(input, header.size as usize);
let mut map_input = input.split_to(header.size as usize);
let count = header.count / 2;
let mut map = Vec::with_capacity(count as usize);
Expand All @@ -297,6 +300,7 @@ impl DecodeFormatted for VecSymbolMap {
impl DecodeFormatted for VecStringMap {
fn decode_with_format(input: &mut Bytes, fmt: u8) -> Result<Self, AmqpParseError> {
let header = decode_map_header(input, fmt)?;
decode_check_len!(input, header.size as usize);
let mut map_input = input.split_to(header.size as usize);
let count = header.count / 2;
let mut map = Vec::with_capacity(count as usize);
Expand Down
2 changes: 1 addition & 1 deletion codec/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl Decoder for ProtocolIdCodec {
if src.len() < PROTOCOL_HEADER_LEN {
Ok(None)
} else {
let src = src.split_to(8);
let src = src.split_to(PROTOCOL_HEADER_LEN);
if &src[0..4] != PROTOCOL_HEADER_PREFIX {
Err(ProtocolIdError::InvalidHeader)
} else if &src[5..8] != PROTOCOL_VERSION {
Expand Down

0 comments on commit 49a3fad

Please sign in to comment.