Skip to content

Commit

Permalink
Check if directories are safe before hashing them.
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt committed Feb 8, 2023
1 parent 1417b98 commit 2d9d5c3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
25 changes: 23 additions & 2 deletions src/evaluate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,27 @@ function evaluate_compiled_test(config::Configuration, pkg::Package;
end


# check for entries that GitTools.tree_hash doesn't handle (Pkg.jl#3365).
# chardev entries indicate a whiteout file, which isn't cacheable anyway.
function is_hasheable(path)
try
if isdir(path)
for entry in readdir(path; join=true)
if !is_hasheable(entry)
return false
end
end
elseif !isfile(path)
return false
end
return true
catch err
# -ELOOP, etc
@error "Encountered broken filesystem entry '$path'" exception=(err,catch_backtrace())
return false
end
end

function verify_artifacts(artifacts; show_status::Bool=true)
removals = []
removals_lock = ReentrantLock()
Expand Down Expand Up @@ -799,7 +820,7 @@ function verify_artifacts(artifacts; show_status::Bool=true)
p = Progress(length(jobs); desc="Verifying artifacts: ",
enabled=isinteractive() && show_status)
@threads for (path, tree_hash) in jobs
if tree_hash != Base.SHA1(Pkg.GitTools.tree_hash(path))
if !is_hasheable(path) || Base.SHA1(Pkg.GitTools.tree_hash(path)) != tree_hash
# remove corrupt artifacts
@debug "A broken artifact was found: $entry"
lock(removals_lock) do
Expand Down Expand Up @@ -914,7 +935,7 @@ function remove_uncacheable_packages(registry, package_dir; show_status::Bool=tr
# because that would result in the build script not being run.
@debug "Package $(name) has a build script, and cannot be cached"
remove = true
elseif Base.SHA1(Pkg.GitTools.tree_hash(path)) != tree_hash
elseif !is_hasheable(path) || Base.SHA1(Pkg.GitTools.tree_hash(path)) != tree_hash
# the contents of the package should match what's in the registry,
# so that we don't cache broken checkouts or other weirdness.
@debug "Package $(name) has been modified, and cannot be cached"
Expand Down
2 changes: 1 addition & 1 deletion src/sandbox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ function run_sandbox(config::Configuration, setup, args...; workdir=nothing, wai
mkpath(bundle_path)
config_path = joinpath(bundle_path, "config.json")
open(config_path, "w") do io
JSON3.write(io, sandbox_config)
JSON3.pretty(io, JSON3.write(sandbox_config))
end

proc = run(pipeline(`$(crun()) --systemd-cgroup --root $(container_root) run --bundle $bundle_path $(sandbox.name)`;
Expand Down

0 comments on commit 2d9d5c3

Please sign in to comment.