diff options
author | KN4CK3R <admin@oldschoolhack.me> | 2024-02-22 04:48:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-22 03:48:19 +0000 |
commit | d6811baf88ca6d58b92d4dc12b1f2a292198751f (patch) | |
tree | 95e35c3e2da9b468b10f2ca265d75c609f4929c7 /modules/git/blob_nogogit.go | |
parent | c236e64aca42b9ab0743431bc505033a0cb78b93 (diff) | |
download | gitea-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.go | 24 |
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) } |