Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
guzba committed Oct 25, 2020
1 parent ec6fdd1 commit 8c003f5
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/zippy.nim
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ func initHuffman(lengths: seq[uint8], maxCodes: int): Huffman =

for symbol in 0 ..< lengths.len:
if lengths[symbol] != 0:
result.symbols[offsets[lengths[symbol]]] = symbol.uint16
let offset = offsets[lengths[symbol]]
if offset.int >= result.symbols.len:
failUncompress()
result.symbols[offset] = symbol.uint16
inc offsets[lengths[symbol]]

func decodeSymbol(b: var Buffer, h: Huffman): uint16 {.inline.} =
Expand Down Expand Up @@ -221,7 +224,7 @@ func inflateBlock(b: var Buffer, dst: var seq[uint8], fixedCodes: bool) =
else:
let lengthIndex = symbol - 257

if lengthIndex >= 30:
if lengthIndex >= baseLengths.len:
failUncompress()

let
Expand All @@ -231,7 +234,7 @@ func inflateBlock(b: var Buffer, dst: var seq[uint8], fixedCodes: bool) =
).int
distCode = decodeSymbol(b, distanceHuffman)

if distCode >= 30:
if distCode >= baseDistance.len:
failUncompress()

let
Expand Down

0 comments on commit 8c003f5

Please sign in to comment.