Skip to content

Commit

Permalink
FIX: failed decompress when input data was not at head
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Sep 23, 2021
1 parent 9f15dac commit 552ec9b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core/u-compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void Trap_ZStream_Error(z_stream *stream, int err, REBOOL while_compression)
} else {
// Get the uncompressed size from last 4 source data bytes.
if (len < 4) Trap0(RE_PAST_END); // !!! better msg needed
size = cast(REBU64, Bytes_To_REBCNT(BIN_SKIP(input, len) - sizeof(REBCNT)));
size = cast(REBU64, Bytes_To_REBCNT(BIN_SKIP(input, index + len) - sizeof(REBCNT)));
if (size > (uLongf)len * 14) Trap_Num(RE_SIZE_LIMIT, size); // check for a realistic limit
}

Expand Down Expand Up @@ -322,7 +322,7 @@ static const ISzAlloc g_Alloc = { SzAlloc, SzFree };
destLen = limit;
} else {
// Get the uncompressed size from last 4 source data bytes.
destLen = cast(REBU64, Bytes_To_REBCNT(BIN_SKIP(input, in_len) - sizeof(REBCNT)));
destLen = cast(REBU64, Bytes_To_REBCNT(BIN_SKIP(input, index + in_len) - sizeof(REBCNT)));
}

output = Make_Binary(destLen);
Expand Down
11 changes: 11 additions & 0 deletions src/tests/units/compress-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,24 @@ data: "test test test"
--assert #{74657374} = decompress compress/part skip data 5 4
--assert #{74657374} = decompress compress/part tail data -4

--test-- "decompress when not at head"
--assert data = to string! decompress next join #{00} compress data

===end-group===

===start-group=== "GZIP compression / decompression"

--test-- "DEFLATE decompress"
--assert #{74657374} = decompress/deflate #{2B492D2E01000C7E7FD804}
--test-- "DEFLATE decompress when not at head"
--assert #{74657374} = decompress/deflate next #{002B492D2E01000C7E7FD804}

--test-- "GZIP compress/decompress"
--assert data = to string! decompress/gzip compress/gzip data

--test-- "GZIP decompress when not at head"
--assert data = to string! decompress/gzip next join #{00} compress/gzip data

--test-- "GZIP compress/decompress while specifing level of compression"
--assert (skip compress/gzip/level "" 0 10) =
#{010000FFFF0000000000000000}
Expand Down Expand Up @@ -116,6 +124,9 @@ data: "test test test"
--assert #{74657374} = decompress/lzma compress/lzma/part data 4
--assert #{74657374} = decompress/lzma compress/lzma/part skip data 5 4
--assert #{74657374} = decompress/lzma compress/lzma/part tail data -4

--test-- "LZMA decompress when not at head"
--assert data = to string! decompress/lzma next join #{00} compress/lzma data
]
===end-group===

Expand Down

0 comments on commit 552ec9b

Please sign in to comment.