Skip to content

Commit 50812f1

Browse files
authored
Fix variable name in git_file_hash() error path (#62)
Also add a test case that hits this error path.
1 parent 0a26553 commit 50812f1

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/extract.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ function git_file_hash(
170170
while size > 0
171171
n = min(t, length(buf))
172172
r = readbytes!(tar, buf, n)
173-
r < n && eof(io) && error("premature end of tar file")
173+
r < n && eof(tar) && throw(EOFError())
174174
v = view(buf, 1:min(r, size))
175175
SHA.update!(ctx, v)
176176
size -= length(v)

test/runtests.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ end
8484
rm(tarball)
8585
end
8686

87+
@testset "truncated tarball" begin
88+
tarball, hash = make_test_tarball()
89+
open(tarball, "a") do io
90+
truncate(io, div(filesize(tarball),2))
91+
end
92+
93+
@testset "tree_hash" begin
94+
# Ensure that this throws
95+
@test_throws EOFError Tar.tree_hash(tarball)
96+
end
97+
end
98+
8799
if !Sys.iswindows()
88100
@testset "POSIX extended headers" begin
89101
# make a test POSIX tarball with GNU `tar` from Tar_jll instead of Tar.create

0 commit comments

Comments
 (0)