1
0
Fork 0
mirror of https://github.com/imjasonh/kontain.me synced 2026-07-18 14:47:48 +00:00

git: assert objects stay packed in the layer

Guards against a regression where go-git would unpack the fetched packfile
into loose objects, which would put the repo's whole decompressed contents in
memory.

https://claude.ai/code/session_01Jfhuuwb5haNaasc9hs53jw
This commit is contained in:
Claude 2026-05-12 15:28:42 +00:00
parent 61e2ace4bc
commit b00925bf9e
No known key found for this signature in database

View file

@ -130,13 +130,22 @@ func TestGitLayer(t *testing.T) {
}
}
hasPack := false
objectsDir := path.Join(prefix, ".git", "objects")
for name := range got {
if strings.HasPrefix(name, path.Join(prefix, ".git", "objects", "pack")+"/") && strings.HasSuffix(name, ".pack") {
if strings.HasPrefix(name, path.Join(objectsDir, "pack")+"/") && strings.HasSuffix(name, ".pack") {
hasPack = true
}
// The objects must stay packed: nothing should be unpacked into loose
// objects/<2-hex>/<38-hex>. If that ever happens the whole repo's
// decompressed contents would be sitting in memory.
if rest, ok := strings.CutPrefix(name, objectsDir+"/"); ok {
if dir, _, found := strings.Cut(rest, "/"); found && dir != "pack" && dir != "info" {
t.Errorf("loose object in layer: %s", name)
}
}
}
if !hasPack {
t.Errorf("layer has no packfile under %s/.git/objects/pack/", prefix)
t.Errorf("layer has no packfile under %s/pack/", objectsDir)
}
// Worktree files must match a real checkout exactly.