diff --git a/lib/chibi/tar.scm b/lib/chibi/tar.scm index 358222f0..118149c4 100644 --- a/lib/chibi/tar.scm +++ b/lib/chibi/tar.scm @@ -76,21 +76,24 @@ (let ((in (cond ((string? src) (open-binary-input-file src)) ((bytevector? src) (open-input-bytevector src)) (else src)))) - (let lp ((acc knil)) + (let lp ((acc knil) (empty 0)) (cond - ((eof-object? (peek-u8 in)) + ((or (eof-object? (peek-u8 in)) (>= empty 2)) (close-input-port in) acc) (else - (let* ((tar (read-tar in)) - (bv (read-modulo-bytevector in (tar-size tar) 512))) - (lp (kons tar bv acc)))))))) + (let ((tar (read-tar in))) + (if (and (equal? "" (tar-path tar)) (zero? (tar-size tar))) + (lp acc (+ empty 1)) + (let ((bv (read-modulo-bytevector in (tar-size tar) 512))) + (lp (kons tar bv acc) 0))))))))) ;; not a tar-bomb and no absolute paths (define (tar-safe? tarball) (define (path-top path) (substring path 0 (string-find path #\/))) (let ((files (map path-normalize (tar-files tarball)))) + (log-error "files: " files) (and (every path-relative? files) (or (< (length files) 2) (let ((dir (path-top (car files))))