diff --git a/src/extract.jl b/src/extract.jl index fb885ae..54e1c3d 100644 --- a/src/extract.jl +++ b/src/extract.jl @@ -520,14 +520,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 0000000..814795e Binary files /dev/null and b/test/data/LF10-fragment.tar differ diff --git a/test/runtests.jl b/test/runtests.jl index f4e1999..9452348 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -844,3 +844,11 @@ if Sys.iswindows() && Sys.which("icacls") !== nothing && VERSION >= 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