if err != nil {
return nil, err
}
+
+ // Make sure directoryOffset points to somewhere in our file.
+ if o := int64(d.directoryOffset); o < 0 || o >= size {
+ return nil, ErrFormat
+ }
return d, nil
}
if b[i] == 'P' && b[i+1] == 'K' && b[i+2] == 0x05 && b[i+3] == 0x06 {
// n is length of comment
n := int(b[i+directoryEndLen-2]) | int(b[i+directoryEndLen-1])<<8
- if n+directoryEndLen+i == len(b) {
+ if n+directoryEndLen+i <= len(b) {
return i
}
}
},
},
},
+ {
+ Name: "test-trailing-junk.zip",
+ Comment: "This is a zipfile comment.",
+ File: []ZipTestFile{
+ {
+ Name: "test.txt",
+ Content: []byte("This is a test text file.\n"),
+ Mtime: "09-05-10 12:12:02",
+ Mode: 0644,
+ },
+ {
+ Name: "gophercolor16x16.png",
+ File: "gophercolor16x16.png",
+ Mtime: "09-05-10 15:52:58",
+ Mode: 0644,
+ },
+ },
+ },
{
Name: "r.zip",
Source: returnRecursiveZip,
}
}
if err != zt.Error {
- t.Errorf("error=%v, want %v", err, zt.Error)
+ t.Errorf("%s: error=%v, want %v", zt.Name, err, zt.Error)
return
}