XL/fs: GetObject should validate all its inputs. (#2142)

Fixes #2141
Fixes #2139
This commit is contained in:
Harshavardhana
2016-07-08 07:46:49 -07:00
committed by GitHub
parent ca1b1921c4
commit ec35330ebb
6 changed files with 79 additions and 51 deletions
+12 -2
View File
@@ -221,14 +221,24 @@ func (fs fsObjects) GetObject(bucket, object string, offset int64, length int64,
if offset < 0 || length < 0 {
return toObjectErr(errUnexpected, bucket, object)
}
// Writer cannot be nil.
if writer == nil {
return toObjectErr(errUnexpected, bucket, object)
}
// Stat the file to get file size.
fi, err := fs.storage.StatFile(bucket, object)
if err != nil {
return toObjectErr(err, bucket, object)
}
if offset > fi.Size {
return InvalidRange{}
// Reply back invalid range if the input offset and length fall out of range.
if offset > fi.Size || length > fi.Size {
return InvalidRange{offset, length, fi.Size}
}
// Reply if we have inputs with offset and length falling out of file size range.
if offset+length > fi.Size {
return InvalidRange{offset, length, fi.Size}
}
var totalLeft = length