Skip to content

Commit

Permalink
Fix endianness when reading the extra field of a gzip header
Browse files Browse the repository at this point in the history
As specified in RFC1952 §2.1 multi-byte values are stored in little
endian format.
  • Loading branch information
Nemo157 committed Oct 8, 2022
1 parent 7932607 commit 7118845
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/codec/gzip/header.rs
Expand Up @@ -85,7 +85,7 @@ impl Parser {
data.copy_unwritten_from(input);

if data.unwritten().is_empty() {
let len = u16::from_be_bytes(data.take().into_inner());
let len = u16::from_le_bytes(data.take().into_inner());
self.state = State::Extra(vec![0; usize::from(len)].into());
} else {
return Ok(None);
Expand Down
1 change: 1 addition & 0 deletions tests/gzip.rs
Expand Up @@ -109,6 +109,7 @@ fn compress_with_header(data: &[u8]) -> Vec<u8> {
let mut gz = GzBuilder::new()
.filename("hello_world.txt")
.comment("test file, please delete")
.extra(vec![1, 2, 3, 4])
.write(&mut bytes, Compression::fast());

gz.write_all(data).unwrap();
Expand Down

0 comments on commit 7118845

Please sign in to comment.