Discard unread data of git cat-file (#29297) (#29310)

Backport #29297 by @KN4CK3R

Fixes #29101
Related #29298

Discard all read data to prevent misinterpreting existing data. Some
discard calls were missing in error cases.

Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
Co-authored-by: yp05327 <576951401@qq.com>
This commit is contained in:
Giteabot 2024-02-22 12:23:38 +08:00 committed by GitHub
parent 0870e0bc9b
commit ed5e0c8c27
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 66 additions and 80 deletions

View file

@ -7,7 +7,6 @@ package git
import (
"io"
"math"
"strings"
)
@ -63,19 +62,8 @@ func (t *Tree) ListEntries() (Entries, error) {
}
// Not a tree just use ls-tree instead
for sz > math.MaxInt32 {
discarded, err := rd.Discard(math.MaxInt32)
sz -= int64(discarded)
if err != nil {
return nil, err
}
}
for sz > 0 {
discarded, err := rd.Discard(int(sz))
sz -= int64(discarded)
if err != nil {
return nil, err
}
if err := DiscardFull(rd, sz+1); err != nil {
return nil, err
}
}