Skip to content

Commit

Permalink
read_header_int: allow leading spaces (fix #111)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
StefanKarpinski committed Jun 4, 2021
1 parent 343e923 commit ed0c4d2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/extract.jl
Expand Up @@ -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

Expand Down
Binary file added test/data/LF10-fragment.tar
Binary file not shown.
8 changes: 8 additions & 0 deletions test/runtests.jl
Expand Up @@ -867,3 +867,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

0 comments on commit ed0c4d2

Please sign in to comment.