From 1600bc5dc6a4217c2f21f35834bfac73a7951cf5 Mon Sep 17 00:00:00 2001 From: Lassi Kortela Date: Mon, 25 Mar 2019 02:33:52 +0200 Subject: [PATCH] file/untar: allow leading as well as trailing blanks (#2553) Some really old tar files can have both leading and trailing blanks (nul/space characters) in the same octal number field in the header. --- racket/collects/file/untar.rkt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/racket/collects/file/untar.rkt b/racket/collects/file/untar.rkt index e9fb83ff2c..4fd1f545c1 100644 --- a/racket/collects/file/untar.rkt +++ b/racket/collects/file/untar.rkt @@ -212,6 +212,12 @@ #f] [else ;; traditional: + (define skip-head + (or (for/or ([i (in-range len)]) + (case (integer->char (bytes-ref bstr i)) + [(#\space #\nul) #f] + [else i])) + (error 'untar "bad number ~e at ~a" bstr (file-position in)))) (define skip-tail (- len (or (for/or ([i (in-range len 0 -1)]) @@ -219,7 +225,7 @@ [(#\space #\nul) #f] [else i])) (error 'untar "bad number ~e at ~a" bstr (file-position in))))) - (for/fold ([v 0]) ([i (in-range (- len skip-tail))]) + (for/fold ([v 0]) ([i (in-range skip-head (- len skip-tail))]) (define b (bytes-ref bstr i)) (if (<= (char->integer #\0) b (char->integer #\7)) (+ (* v 8) (- b (char->integer #\0)))