|
@@ -138,7 +138,13 @@ func (tr *Reader) Next() (*Header, error) {
|
|
// We actually read the whole file,
|
|
// We actually read the whole file,
|
|
// but this skips alignment padding
|
|
// but this skips alignment padding
|
|
tr.skipUnread()
|
|
tr.skipUnread()
|
|
|
|
+ if tr.err != nil {
|
|
|
|
+ return nil, tr.err
|
|
|
|
+ }
|
|
hdr = tr.readHeader()
|
|
hdr = tr.readHeader()
|
|
|
|
+ if hdr == nil {
|
|
|
|
+ return nil, tr.err
|
|
|
|
+ }
|
|
mergePAX(hdr, headers)
|
|
mergePAX(hdr, headers)
|
|
|
|
|
|
// Check for a PAX format sparse file
|
|
// Check for a PAX format sparse file
|
|
@@ -397,7 +403,7 @@ func parsePAX(r io.Reader) (map[string]string, error) {
|
|
}
|
|
}
|
|
// Parse the first token as a decimal integer.
|
|
// Parse the first token as a decimal integer.
|
|
n, err := strconv.ParseInt(string(buf[:sp]), 10, 0)
|
|
n, err := strconv.ParseInt(string(buf[:sp]), 10, 0)
|
|
- if err != nil {
|
|
|
|
|
|
+ if err != nil || n < 5 || int64(len(buf)) < n {
|
|
return nil, ErrHeader
|
|
return nil, ErrHeader
|
|
}
|
|
}
|
|
// Extract everything between the decimal and the n -1 on the
|
|
// Extract everything between the decimal and the n -1 on the
|
|
@@ -553,6 +559,10 @@ func (tr *Reader) readHeader() *Header {
|
|
hdr.Uid = int(tr.octal(s.next(8)))
|
|
hdr.Uid = int(tr.octal(s.next(8)))
|
|
hdr.Gid = int(tr.octal(s.next(8)))
|
|
hdr.Gid = int(tr.octal(s.next(8)))
|
|
hdr.Size = tr.octal(s.next(12))
|
|
hdr.Size = tr.octal(s.next(12))
|
|
|
|
+ if hdr.Size < 0 {
|
|
|
|
+ tr.err = ErrHeader
|
|
|
|
+ return nil
|
|
|
|
+ }
|
|
hdr.ModTime = time.Unix(tr.octal(s.next(12)), 0)
|
|
hdr.ModTime = time.Unix(tr.octal(s.next(12)), 0)
|
|
s.next(8) // chksum
|
|
s.next(8) // chksum
|
|
hdr.Typeflag = s.next(1)[0]
|
|
hdr.Typeflag = s.next(1)[0]
|
|
@@ -895,6 +905,9 @@ func (sfr *sparseFileReader) Read(b []byte) (n int, err error) {
|
|
// Otherwise, we're at the end of the file
|
|
// Otherwise, we're at the end of the file
|
|
return 0, io.EOF
|
|
return 0, io.EOF
|
|
}
|
|
}
|
|
|
|
+ if sfr.tot < sfr.sp[0].offset {
|
|
|
|
+ return 0, io.ErrUnexpectedEOF
|
|
|
|
+ }
|
|
if sfr.pos < sfr.sp[0].offset {
|
|
if sfr.pos < sfr.sp[0].offset {
|
|
// We're in a hole
|
|
// We're in a hole
|
|
n = sfr.readHole(b, sfr.sp[0].offset)
|
|
n = sfr.readHole(b, sfr.sp[0].offset)
|