Skip to content

Commit

Permalink
Close file on invalid range (go-gitea#15166)
Browse files Browse the repository at this point in the history
* Close file on invalid range.

* Close on seek error

Co-authored-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
  • Loading branch information
4 people committed Apr 3, 2021
1 parent 33c4e24 commit 0fe6bcb
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions modules/lfs/content_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,21 @@ func (s *ContentStore) Get(meta *models.LFSMetaObject, fromByte int64) (io.ReadC
}
if fromByte > 0 {
if fromByte >= meta.Size {
err = f.Close()
if err != nil {
log.Error("Whilst trying to read LFS OID[%s]: Unable to close Error: %v", meta.Oid, err)
}
return nil, ErrRangeNotSatisfiable{
FromByte: fromByte,
}
}
_, err = f.Seek(fromByte, io.SeekStart)
if err != nil {
log.Error("Whilst trying to read LFS OID[%s]: Unable to seek to %d Error: %v", meta.Oid, fromByte, err)
errClose := f.Close()
if errClose != nil {
log.Error("Whilst trying to read LFS OID[%s]: Unable to close Error: %v", meta.Oid, errClose)
}
}
}
return f, err
Expand Down

0 comments on commit 0fe6bcb

Please sign in to comment.