guzba / zippy

Pure Nim implementation of deflate, zlib, gzip and zip.
MIT License
250 stars 30 forks source link

Program crashes when extracting specific tarball #39

Closed SnwMds closed 2 years ago

SnwMds commented 2 years ago

Code:

import pkg/zippy/tarballs

extractAll(tarPath = "./libressl-3.4.2.tar.gz", dest = "./libressl")

Log:

/home/snwmds/test_zippy.nim(3) test_zippy
/home/snwmds/.nimble/pkgs/zippy-0.9.5/zippy/tarballs.nim(63) extractAll
/home/snwmds/.nimble/pkgs/zippy-0.9.5/zippy/tarballs.nim(14) parseTarOctInt
[[reraised from:
/home/snwmds/test_zippy.nim(3) test_zippy
/home/snwmds/.nimble/pkgs/zippy-0.9.5/zippy/tarballs.nim(129) extractAll
]]
Error: unhandled exception: /home/snwmds/test_zippy.nim(3) test_zippy
/home/snwmds/.nimble/pkgs/zippy-0.9.5/zippy/tarballs.nim(63) extractAll
/home/snwmds/.nimble/pkgs/zippy-0.9.5/zippy/tarballs.nim(12) parseTarOctInt
/home/snwmds/.choosenim/toolchains/nim-1.6.2/lib/pure/strutils.nim(1143) parseOctInt
invalid oct integer: 100664  [ZippyError]

Tarball: https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-3.4.2.tar.gz

guzba commented 2 years ago

Wow tar stores these numbers in just a horrible format. Hmm, how should I even parse this number? It is 8 bytes ascii digits oct encoded null-terminated monster.

And apparently null-terminated wasn't enough, this file has a space before the null-terminator, insane. I think I'll just walk the bytes and assume the number starts at the first ascii digit and ends when I reach a character that isn't an ascii number. Crazy crazy but I guess tar is ancient.

Did this and tagged release 0.9.7. I look forward to the next tar oct int bug lol.

SnwMds commented 2 years ago

Thanks for the quick fix!