aboutsummaryrefslogtreecommitdiffstats
path: root/modules/git/blob_nogogit.go
diff options
context:
space:
mode:
authorKN4CK3R <admin@oldschoolhack.me>2024-02-22 04:48:19 +0100
committerGitHub <noreply@github.com>2024-02-22 03:48:19 +0000
commitd6811baf88ca6d58b92d4dc12b1f2a292198751f (patch)
tree95e35c3e2da9b468b10f2ca265d75c609f4929c7 /modules/git/blob_nogogit.go
parentc236e64aca42b9ab0743431bc505033a0cb78b93 (diff)
downloadgitea-d6811baf88ca6d58b92d4dc12b1f2a292198751f.tar.gz
gitea-d6811baf88ca6d58b92d4dc12b1f2a292198751f.zip
Discard unread data of `git cat-file` (#29297)
Fixes #29101 Related #29298 Discard all read data to prevent misinterpreting existing data. Some discard calls were missing in error cases. --------- Co-authored-by: yp05327 <576951401@qq.com>
Diffstat (limited to 'modules/git/blob_nogogit.go')
-rw-r--r--modules/git/blob_nogogit.go24
1 files changed, 2 insertions, 22 deletions
diff --git a/modules/git/blob_nogogit.go b/modules/git/blob_nogogit.go
index 6e8a48b1db..9e1c2a0376 100644
--- a/modules/git/blob_nogogit.go
+++ b/modules/git/blob_nogogit.go
@@ -9,7 +9,6 @@ import (
"bufio"
"bytes"
"io"
- "math"
"code.gitea.io/gitea/modules/log"
)
@@ -104,25 +103,6 @@ func (b *blobReader) Read(p []byte) (n int, err error) {
// Close implements io.Closer
func (b *blobReader) Close() error {
defer b.cancel()
- if b.n > 0 {
- for b.n > math.MaxInt32 {
- n, err := b.rd.Discard(math.MaxInt32)
- b.n -= int64(n)
- if err != nil {
- return err
- }
- b.n -= math.MaxInt32
- }
- n, err := b.rd.Discard(int(b.n))
- b.n -= int64(n)
- if err != nil {
- return err
- }
- }
- if b.n == 0 {
- _, err := b.rd.Discard(1)
- b.n--
- return err
- }
- return nil
+
+ return DiscardFull(b.rd, b.n+1)
}