Skip to content

Commit 470883c

Browse files
committed
Fix crash when GetAllChildren returns nil,nil
When GetAllChildren return nil, nil the following panic happens panic: runtime error: makeslice: cap out of range goroutine 1 [running]: iso9660.(*File).GetChildren(0x54ec60?) /home/tzachmann/develop/test/go/iso9660/src/iso9660/image_reader.go:254 +0x51 Here is the code that is problematic. When GetAllChildren returns nil, nil make with a size of -2 will be called which results in the above panic. func (f *File) GetChildren() ([]*File, error) { children, err := f.GetAllChildren() if err != nil { return nil, err } filteredChildren := make([]*File, 0, len(children)-2) This patch returns an error in case there are no children or the ReadAt fails. If in this cases a nil, nil is fine the above code could be changed to filteredChildren := make([]*File, 0, len(children)) to fix the problem.
1 parent 4c03881 commit 470883c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

image_reader.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func (f *File) GetAllChildren() ([]*File, error) {
179179
buffer := make([]byte, sectorSize)
180180
for bytesProcessed := uint32(0); bytesProcessed < uint32(f.de.ExtentLength); bytesProcessed += sectorSize {
181181
if _, err := f.ra.ReadAt(buffer, int64(baseOffset+bytesProcessed)); err != nil {
182-
return nil, nil
182+
return nil, err
183183
}
184184

185185
for i := uint32(0); i < sectorSize; {
@@ -239,6 +239,9 @@ func (f *File) GetAllChildren() ([]*File, error) {
239239
f.children = append(f.children, newFile)
240240
}
241241
}
242+
if f.children == nil {
243+
return nil, fmt.Errorf("no children found")
244+
}
242245

243246
return f.children, nil
244247
}

0 commit comments

Comments
 (0)