Commit 470883c
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
1 file changed
+4
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
182 | | - | |
| 182 | + | |
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
| |||
239 | 239 | | |
240 | 240 | | |
241 | 241 | | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
242 | 245 | | |
243 | 246 | | |
244 | 247 | | |
| |||
0 commit comments