Skip to content

Commit 8d75e3d

Browse files
authored
Merge pull request #62 from guzba/ryan
0.9.10 add breach mitigation
2 parents 3b863db + f1fd90b commit 8d75e3d

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/zippy.nim

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
import zippy/adler32, zippy/common, zippy/crc, zippy/deflate, zippy/gzip,
2-
zippy/inflate, zippy/internal
1+
import zippy/adler32, zippy/common, zippy/crc, zippy/deflate,
2+
zippy/gzip, zippy/inflate, zippy/internal
3+
4+
when (NimMajor, NimMinor, NimPatch) >= (1, 6, 0):
5+
import std/sysrand
6+
else:
7+
import std/random, std/times
38

49
export common
510

@@ -18,6 +23,23 @@ proc compress*(
1823
result[0] = 31.char
1924
result[1] = 139.char
2025
result[2] = 8.char
26+
result[3] = (1.uint8 shl 3).char # Set the fname flag
27+
28+
block: # https://github.com/guzba/zippy/issues/61
29+
let htbLen =
30+
when (NimMajor, NimMinor, NimPatch) >= (1, 6, 0):
31+
var urand: array[1, uint8]
32+
if not urandom(urand):
33+
raise newException(ZippyError, "Failed to generate random number")
34+
(urand[0] mod 26).int
35+
else:
36+
let now = getTime()
37+
var rand = initRand(now.toUnix * 1_000_000_000 + now.nanosecond)
38+
(rand.next() mod 26).int # mod the uint first to ensure a positive int
39+
# Add up to 26 characters as the gzip header file name
40+
for i in 0 ..< htbLen:
41+
result.add (97 + i).char
42+
result.add '\0'
2143

2244
deflate(result, src, len, level)
2345

zippy.nimble

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version = "0.10.8"
1+
version = "0.10.9"
22
author = "Ryan Oldenburg"
33
description = "Pure Nim implementation of deflate, zlib, gzip and zip."
44
license = "MIT"

0 commit comments

Comments
 (0)