Invalid output in batch_reader.go #12458

Closed
opened 2025-11-02 10:10:25 -06:00 by GiteaMirror · 2 comments
Owner

Originally created by @KN4CK3R on GitHub (Feb 8, 2024).

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
ce9978bfd4/modules/actions/workflows.go (L47-L50)

which fails in line 179
ce9978bfd4/modules/git/batch_reader.go (L152-L181)

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

Originally created by @KN4CK3R on GitHub (Feb 8, 2024). `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 https://github.com/go-gitea/gitea/blob/ce9978bfd4e035ed065b02b28e02905674320b6a/modules/actions/workflows.go#L47-L50 which fails in line 179 https://github.com/go-gitea/gitea/blob/ce9978bfd4e035ed065b02b28e02905674320b6a/modules/git/batch_reader.go#L152-L181 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
GiteaMirror added the type/bug label 2025-11-02 10:10:25 -06:00
Author
Owner

@KN4CK3R commented on GitHub (Feb 8, 2024):

Stacktrace:

code.gitea.io/gitea/modules/git.ReadBatchLine(0xc0034f5008?)
        /src/modules/git/batch_reader.go:182 +0x1c8
code.gitea.io/gitea/modules/git.(*Repository).getTree(0xc005f8c870, {0x3a90360, 0xc0034f5008})
        /src/modules/git/repo_tree_nogogit.go:19 +0xf0
code.gitea.io/gitea/modules/git.(*Tree).SubTree(0xc004ba2f70, {0x327c01b?, 0x316d8c8?})
        /src/modules/git/tree.go:42 +0x1a5
code.gitea.io/gitea/modules/actions.ListWorkflows(0xc004ba2f70)
        /src/modules/actions/workflows.go:50 +0x85
code.gitea.io/gitea/routers/web/repo/actions.List(0xc004be8c80)
        /src/routers/web/repo/actions/actions.go:74 +0x1d7
@KN4CK3R commented on GitHub (Feb 8, 2024): Stacktrace: ``` code.gitea.io/gitea/modules/git.ReadBatchLine(0xc0034f5008?) /src/modules/git/batch_reader.go:182 +0x1c8 code.gitea.io/gitea/modules/git.(*Repository).getTree(0xc005f8c870, {0x3a90360, 0xc0034f5008}) /src/modules/git/repo_tree_nogogit.go:19 +0xf0 code.gitea.io/gitea/modules/git.(*Tree).SubTree(0xc004ba2f70, {0x327c01b?, 0x316d8c8?}) /src/modules/git/tree.go:42 +0x1a5 code.gitea.io/gitea/modules/actions.ListWorkflows(0xc004ba2f70) /src/modules/actions/workflows.go:50 +0x85 code.gitea.io/gitea/routers/web/repo/actions.List(0xc004be8c80) /src/routers/web/repo/actions/actions.go:74 +0x1d7 ```
Author
Owner

@yp05327 commented on GitHub (Feb 19, 2024):

cat-file --batch will output <sha> SP <type> SP <size> LF\n<content>
After some tests, I notice that:
normally, reader buffer will not be empty after read one line, as we have <content> behind.
but reader buffer will randomly be empty after read one line, e.g. we will get <sha> SP <type> SP <size> LF\n in reader bugger without content. And the content will be read at the next time, which caused this bug.

Some related codes:
f04e71f9bc/modules/git/repo_base_nogogit.go (L81-L86)
if repo.batchReader.Buffered() is 0, as what mentioned above, reader buffer will randomly be empty after read one line,
CatFileBatch will return the existing reader buffer , and in for loop in func SubTree, in the next time, func getTree will read <content> as the first line.

@yp05327 commented on GitHub (Feb 19, 2024): `cat-file --batch` will output `<sha> SP <type> SP <size> LF\n<content>` After some tests, I notice that: normally, reader buffer will not be empty after read one line, as we have `<content>` behind. but reader buffer will randomly be empty after read one line, e.g. we will get `<sha> SP <type> SP <size> LF\n` in reader bugger without content. And the `content` will be read at the next time, which caused this bug. Some related codes: https://github.com/go-gitea/gitea/blob/f04e71f9bc05d4930e1eff0b69ceb0e890528e30/modules/git/repo_base_nogogit.go#L81-L86 if `repo.batchReader.Buffered()` is 0, as what mentioned above, reader buffer will randomly be empty after read one line, `CatFileBatch` will return the existing reader buffer , and in for loop in func `SubTree`, in the next time, func `getTree` will read `<content>` as the first line.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#12458