diff --git a/src/zippy.nim b/src/zippy.nim index adcfaf2..41f30cb 100644 --- a/src/zippy.nim +++ b/src/zippy.nim @@ -145,6 +145,9 @@ func uncompress( # raise newException(ZippyError, "Header checksum verification failed") inc(pos, 2) + if pos + 8 >= src.len: + failUncompress() + inflate(src[pos ..< ^8], dst) let checksum = read32(src, src.len - 8) diff --git a/tests/stress.nim b/tests/stress.nim index 84171f1..1699db8 100644 --- a/tests/stress.nim +++ b/tests/stress.nim @@ -1,4 +1,4 @@ -import random, times, zippy +import random, times, zippy, zip/zlib # Generate random blobs of data containing runs of random lengths. Ensure # we can always compress this blob and that uncompressing the compressed @@ -42,10 +42,18 @@ for i in 0 ..< 10000: compressed = compress(data) uncompressed = uncompress(compressed) doAssert uncompressed == data + doAssert zlib.uncompress( + cast[string](compressed), + stream = GZIP_STREAM + ) == cast[string](data) fuzz() block: # shuffled var compressed = compress(shuffled) uncompressed = uncompress(compressed) doAssert uncompressed == shuffled + doAssert zlib.uncompress( + cast[string](compressed), + stream = GZIP_STREAM + ) == cast[string](shuffled) fuzz() diff --git a/zippy.nimble b/zippy.nimble index b5f2351..ad8a0d2 100644 --- a/zippy.nimble +++ b/zippy.nimble @@ -1,5 +1,5 @@ packageName = "zippy" -version = "0.3.0" +version = "0.3.1" author = "Ryan Oldenburg" description = "In-progress pure Nim implementation of deflate and zlib." license = "MIT"