This commit is contained in:
Ryan Oldenburg 2020-11-12 02:32:52 -06:00
parent e10776624d
commit f1d27c1eb3
3 changed files with 13 additions and 2 deletions

View File

@ -145,6 +145,9 @@ func uncompress(
# raise newException(ZippyError, "Header checksum verification failed") # raise newException(ZippyError, "Header checksum verification failed")
inc(pos, 2) inc(pos, 2)
if pos + 8 >= src.len:
failUncompress()
inflate(src[pos ..< ^8], dst) inflate(src[pos ..< ^8], dst)
let checksum = read32(src, src.len - 8) let checksum = read32(src, src.len - 8)

View File

@ -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 # Generate random blobs of data containing runs of random lengths. Ensure
# we can always compress this blob and that uncompressing the compressed # we can always compress this blob and that uncompressing the compressed
@ -42,10 +42,18 @@ for i in 0 ..< 10000:
compressed = compress(data) compressed = compress(data)
uncompressed = uncompress(compressed) uncompressed = uncompress(compressed)
doAssert uncompressed == data doAssert uncompressed == data
doAssert zlib.uncompress(
cast[string](compressed),
stream = GZIP_STREAM
) == cast[string](data)
fuzz() fuzz()
block: # shuffled block: # shuffled
var var
compressed = compress(shuffled) compressed = compress(shuffled)
uncompressed = uncompress(compressed) uncompressed = uncompress(compressed)
doAssert uncompressed == shuffled doAssert uncompressed == shuffled
doAssert zlib.uncompress(
cast[string](compressed),
stream = GZIP_STREAM
) == cast[string](shuffled)
fuzz() fuzz()

View File

@ -1,5 +1,5 @@
packageName = "zippy" packageName = "zippy"
version = "0.3.0" version = "0.3.1"
author = "Ryan Oldenburg" author = "Ryan Oldenburg"
description = "In-progress pure Nim implementation of deflate and zlib." description = "In-progress pure Nim implementation of deflate and zlib."
license = "MIT" license = "MIT"