Skip to content

Commit

Permalink
v1.1.1, fuzzing, bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
guzba committed Oct 25, 2020
1 parent 168873c commit 80b356d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion supersnappy.nim
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func uncompress*(src: openArray[uint8], dst: var seq[uint8]) =

inc(ip, (entry shr 11).int + 1)

if dstLen - op < len or op <= offset - 1: # Catches offset == 0
if dstLen - op < len or op.uint <= offset.uint - 1: # Catches offset == 0
failUncompress()

if len <= 16 and offset >= 8 and dstLen > op + 16:
Expand Down
2 changes: 1 addition & 1 deletion supersnappy.nimble
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
packageName = "supersnappy"
version = "1.1.0"
version = "1.1.1"
author = "Ryan Oldenburg"
description = "Nim implementation of Google's Snappy compression."
license = "MIT"
Expand Down
22 changes: 22 additions & 0 deletions tests/fuzz.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import strformat, random, supersnappy

randomize()

const files = [
"alice29.txt", "asyoulik.txt", "fireworks.jpg", "geo.protodata",
"html", "html_x_4", "kppkn.gtb", "lcet10.txt", "paper-100k.pdf",
"plrabn12.txt", "urls.10K"
]

for i in 0 ..< 10_000:
let file = files[rand(files.len - 1)]
var compressed = readFile(&"tests/data/{file}.snappy")
let
pos = rand(compressed.len - 1)
value = rand(255).char
compressed[pos] = value
echo &"{i} {file} {pos} {value.uint8}"
try:
assert uncompress(compressed).len > 0
except SnappyError:
discard

0 comments on commit 80b356d

Please sign in to comment.