Skip to content
This repository was archived by the owner on Aug 14, 2020. It is now read-only.

Commit 54331ec

Browse files
committed
backend/file: fix an infinite loop in deps walking (CVE-2016-8579)
This commit fixes a possible infinite loop while traversing the dependency ancestry of a malformed local image file. This has been assigned CVE-2016-8579: #203 (comment)
1 parent 8a4173c commit 54331ec

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/internal/backend/file/file.go

+11
Original file line numberDiff line numberDiff line change
@@ -279,14 +279,24 @@ func extractEmbeddedLayer(file *os.File, layerID string, outputPath string) (*os
279279
return layerFile, nil
280280
}
281281

282+
// getAncestry computes an image ancestry, returning an ordered list
283+
// of dependencies starting from the topmost image to the base.
284+
// It checks for dependency loops via duplicate detection in the image
285+
// chain and errors out in such cases.
282286
func getAncestry(file *os.File, imgID string) ([]string, error) {
283287
var ancestry []string
288+
deps := make(map[string]bool)
284289

285290
curImgID := imgID
286291

287292
var err error
288293
for curImgID != "" {
294+
if deps[curImgID] {
295+
return nil, fmt.Errorf("dependency loop detected at image %q", curImgID)
296+
}
297+
deps[curImgID] = true
289298
ancestry = append(ancestry, curImgID)
299+
log.Debug(fmt.Sprintf("Getting ancestry for layer %q", curImgID))
290300
curImgID, err = getParent(file, curImgID)
291301
if err != nil {
292302
return nil, err
@@ -328,5 +338,6 @@ func getParent(file *os.File, imgID string) (string, error) {
328338
return "", err
329339
}
330340

341+
log.Debug(fmt.Sprintf("Layer %q depends on layer %q", imgID, parent))
331342
return parent, nil
332343
}

0 commit comments

Comments
 (0)