From ed0c4d2864b421accf7d39d75f02477685cb581a Mon Sep 17 00:00:00 2001 From: Stefan Karpinski Date: Wed, 2 Jun 2021 16:27:59 -0400 Subject: [PATCH] read_header_int: allow leading spaces (fix #111) Some old versions of `tar` (e.g. Solaris) emitted integer fields with leadings *spaces* which is technically contrary to the standard, but seems harmless to support. This adds a fragment of this tarball: https://sparse.tamu.edu/MM/Oberwolfach/LF10.tar.gz This is a collection of example sparse matrix files. The fragment is a single header entry followed by one block of data and is a valid tarball by itself with the idiosyncratic field formatting of Solaris `tar`. --- src/extract.jl | 7 ++++++- test/data/LF10-fragment.tar | Bin 0 -> 1024 bytes test/runtests.jl | 8 ++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 test/data/LF10-fragment.tar diff --git a/src/extract.jl b/src/extract.jl index fdc79d5..ecb06f2 100644 --- a/src/extract.jl +++ b/src/extract.jl @@ -601,14 +601,19 @@ end function read_header_int(buf::AbstractVector{UInt8}, offset::Int, length::Int) n = UInt64(0) - for i in index_range(offset, length) + before = true + r = index_range(offset, length) + for i in r byte = buf[i] + before && byte == UInt8(' ') && continue byte in (0x00, UInt8(' ')) && break UInt8('0') <= byte <= UInt8('7') || error("invalid octal digit: $(repr(Char(byte)))") n <<= 3 n |= byte - 0x30 + before = false end + before && error("invalid integer value: $(repr(String(buf[r])))") return n end diff --git a/test/data/LF10-fragment.tar b/test/data/LF10-fragment.tar new file mode 100644 index 0000000000000000000000000000000000000000..814795e44adbe9c1582b86d6269f2acee68a8c93 GIT binary patch literal 1024 zcmc&yJx{|h6wI7oaZ5IcZ9-F&u|=I)F#t1qIIq-dzGOS3KOZMBMJ$zC^@g+FhtKcy zyxk}%wt+rYY3)zZHK3%-r9^}g^E0FtizSo{oXf{7&j6*ehb)4;#xQfu-g&YiS<<(0 z^Wqut+}s&gZ`qn8JMz|?c4Uw2QBMJM+uG7J)$Ap?ZRXiUY^DT=l= v"1.6" end end end + +@testset "leading spaces" begin + # fragment of https://sparse.tamu.edu/MM/Oberwolfach/LF10.tar.gz + tarball = joinpath(@__DIR__, "data", "LF10-fragment.tar") + @test Tar.list(tarball) == [ + Tar.Header("LF10/LF10_B.mtx", :file, 0o100600, 367, "") + ] +end