Skip to content

Commit 773403a

Browse files
Fix nil pointer dereference in xray command
This commit fixes a nil pointer dereference in the xray command that occurs when analyzing some Docker images. The crash was caused by the `List` function modifying the heap while iterating over it. The fix modifies the `List` function to create a new heap and pop items from the new heap. This prevents the heap from being modified while it's being iterated over.
1 parent a303c88 commit 773403a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pkg/docker/dockerimage/topobjects.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,13 @@ func (to *TopObjects) Pop() interface{} {
5353

5454
func (to TopObjects) List() []*ObjectMetadata {
5555
list := []*ObjectMetadata{}
56-
for len(to) > 0 {
57-
item := heap.Pop(&to).(*ObjectMetadata)
56+
// Create a copy of the heap to avoid modifying the original heap
57+
h := make(TopObjects, len(to))
58+
copy(h, to)
59+
heap.Init(&h)
60+
61+
for len(h) > 0 {
62+
item := heap.Pop(&h).(*ObjectMetadata)
5863
if item == nil {
5964
continue
6065
}

0 commit comments

Comments
 (0)