Skip to content

Invalid output in batch_reader.go #29101

Closed
@KN4CK3R

Description

@KN4CK3R

strconv.ParseInt: parsing "number": invalid syntax

Steps to reproduce:

  1. Create a repository with actions enabled
  2. Create a file /.gitea/workflows with the content not a number
  3. Create a file /.github/workflows with the content not a number
  4. Open the page /<owner>/<repo>/actions
  5. If no error is shown, refresh the page multiple times until an error occurs

The reason is this code

tree, err := commit.SubTree(".gitea/workflows")
if _, ok := err.(git.ErrNotExist); ok {
tree, err = commit.SubTree(".github/workflows")
}

which fails in line 179

func ReadBatchLine(rd *bufio.Reader) (sha []byte, typ string, size int64, err error) {
typ, err = rd.ReadString('\n')
if err != nil {
return sha, typ, size, err
}
if len(typ) == 1 {
typ, err = rd.ReadString('\n')
if err != nil {
return sha, typ, size, err
}
}
idx := strings.IndexByte(typ, ' ')
if idx < 0 {
log.Debug("missing space typ: %s", typ)
return sha, typ, size, ErrNotExist{ID: string(sha)}
}
sha = []byte(typ[:idx])
typ = typ[idx+1:]
idx = strings.IndexByte(typ, ' ')
if idx < 0 {
return sha, typ, size, ErrNotExist{ID: string(sha)}
}
sizeStr := typ[idx+1 : len(typ)-1]
typ = typ[:idx]
size, err = strconv.ParseInt(sizeStr, 10, 64)
return sha, typ, size, err
}

If the error occurs the code tries to parse not a number as output of the batch reader. A normal output looks like 8b2bfd3a117fcb7ae93f93616cb2f7a9706c513a tree 104. I don't know how the content of a file can be present here. And even worse is that it does not fail every time. If I create only one workflows file it does not fail but that may just be a timing issue.

Git Version

2.43.0, non-gogit

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions