Skip to content

Commit ada5209

Browse files
committed
32 bit work
1 parent a0057dc commit ada5209

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/zippy/gzip.nim

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,24 @@ proc uncompressGzip*(
6565
checksum = read32(src, len - 8)
6666
isize = read32(src, len - 4)
6767

68+
when sizeof(int) == 4:
69+
if isize > int.high:
70+
raise newException(ZippyError, "Uncompressed size exceeds max string length")
71+
6872
if trustSize:
69-
dst.setLen(isize + 16) # Leave some room to write past the end
73+
when sizeof(int) == 4:
74+
dst.setLen(isize)
75+
else:
76+
dst.setLen(isize + 16) # Leave some room to write past the end
7077

7178
inflate(dst, src, len, pos)
7279

7380
if checksum != crc32(dst):
7481
raise newException(ZippyError, "Checksum verification failed")
7582

76-
if isize != (dst.len mod (1 shl 32)).uint32:
77-
raise newException(ZippyError, "Size verification failed")
83+
when sizeof(int) == 4:
84+
if isize != dst.len.uint32:
85+
raise newException(ZippyError, "Size verification failed")
86+
else:
87+
if isize != (dst.len mod (1 shl 32)).uint32:
88+
raise newException(ZippyError, "Size verification failed")

0 commit comments

Comments
 (0)