Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting notes of a tag via API triggers panic #23357

Closed
wiktor-k opened this issue Mar 7, 2023 · 0 comments · Fixed by #23372
Closed

Getting notes of a tag via API triggers panic #23357

wiktor-k opened this issue Mar 7, 2023 · 0 comments · Fixed by #23372
Assignees
Labels
Milestone

Comments

@wiktor-k
Copy link
Contributor

wiktor-k commented Mar 7, 2023

Description

Hi,

I've been experimenting with git notes and noticed that notes on tags are not properly handled. See this link: https://try.gitea.io/api/v1/repos/wiktor/dks/git/notes/v1

It triggers the following panic:

2023/03/07 11:58:58 ...common/middleware.go:71:1() [E] [640718f2] PANIC: runtime error: invalid memory address or nil pointer dereference
	/usr/lib/go/src/runtime/panic.go:260 (0x45883c)
		panicmem: panic(memoryError)
	/usr/lib/go/src/runtime/signal_unix.go:837 (0x45880c)
		sigpanic: panicmem()
	/home/wiktor/src/open-source/gitea/modules/git/tree_entry_nogogit.go:93 (0x1019cda)
		(*TreeEntry).Blob: ID:      te.ID,
	/home/wiktor/src/open-source/gitea/modules/git/notes_nogogit.go:56 (0x1019a12)
		GetNote: blob := entry.Blob()
	/home/wiktor/src/open-source/gitea/routers/api/v1/repo/notes.go:62 (0x220f0a4)
		getNote: if err := git.GetNote(ctx, ctx.Repo.GitRepo, identifier, &note); err != nil {

I think the code assumes notes are only for commits and tries to get the Tree but Tags don't have it.

Gitea Version

1.20.0+dev-101-g84a299310

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

No response

How are you running Gitea?

Locally and via try.gitea.io

Database

None

@sillyguodong sillyguodong reopened this Mar 7, 2023
@Zettat123 Zettat123 self-assigned this Mar 8, 2023
lunny pushed a commit that referenced this issue Mar 8, 2023
Fix #23357 .

Now the `/repos/{owner}/{repo}/git/notes/{sha}` API supports getting
notes by a ref or sha
(https://try.gitea.io/api/swagger#/repository/repoGetNote). But the
`GetNote` func can only accept commit ID.

https://github.com/go-gitea/gitea/blob/a12f5757372f751d25f9e5ca1f168f6920ded894/modules/git/notes_nogogit.go#L18

So we need to convert the query parameter to commit ID before calling
`GetNote`.
@lunny lunny added this to the 1.19.0 milestone Mar 8, 2023
GiteaBot pushed a commit to GiteaBot/gitea that referenced this issue Mar 8, 2023
Fix go-gitea#23357 .

Now the `/repos/{owner}/{repo}/git/notes/{sha}` API supports getting
notes by a ref or sha
(https://try.gitea.io/api/swagger#/repository/repoGetNote). But the
`GetNote` func can only accept commit ID.

https://github.com/go-gitea/gitea/blob/a12f5757372f751d25f9e5ca1f168f6920ded894/modules/git/notes_nogogit.go#L18

So we need to convert the query parameter to commit ID before calling
`GetNote`.
techknowlogick added a commit that referenced this issue Mar 8, 2023
Backport #23372

Fix #23357 .

Now the `/repos/{owner}/{repo}/git/notes/{sha}` API supports getting
notes by a ref or sha
(https://try.gitea.io/api/swagger#/repository/repoGetNote). But the
`GetNote` func can only accept commit ID.

https://github.com/go-gitea/gitea/blob/a12f5757372f751d25f9e5ca1f168f6920ded894/modules/git/notes_nogogit.go#L18

So we need to convert the query parameter to commit ID before calling
`GetNote`.

Co-authored-by: Zettat123 <zettat123@gmail.com>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
@go-gitea go-gitea locked and limited conversation to collaborators May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants