"slice bounds out of range error" in signature_nogogit.go due to an empty author name #9872

Closed
opened 2025-11-02 08:51:58 -06:00 by GiteaMirror · 0 comments
Owner

Originally created by @ghost on GitHub (Nov 22, 2022).

Description

Not sure how it happened, I have commits without an author name in a repository.

commit ea187914379a3137a46784c716307a2844dbe744
Author:  <example@example.com>
Date:   Thu Mar 27 12:51:29 2008 +0100

Pushing this repository will lead to a 500 error when visiting the repository page on gitea, due to the following exception :

2022/11/22 17:58:15 routers/web/base.go:135:1() [E] [637cffa7] PANIC: runtime error: slice bounds out of range [:-1]
/usr/lib/go-1.19/src/runtime/panic.go:139 (0x4404be)
	goPanicSliceAcap: panic(boundsError{x: int64(x), signed: true, y: y, code: boundsSliceAcap})
/home/aot/src/gitea/modules/git/signature_nogogit.go:54 (0x100bc3c)
	newSignatureFromCommitline: sig.Name = string(line[:emailStart-1])
/home/aot/src/gitea/modules/git/signature_nogogit.go:33 (0xfbfa5c)
	(*Signature).Decode: sig, _ := newSignatureFromCommitline(b)
/home/aot/src/gitea/modules/git/commit_reader.go:82 (0xfbfa45)
	CommitFromReader: commit.Author.Decode(data)
/home/aot/src/gitea/modules/git/repo_commit_nogogit.go:117 (0xff34c8)
	(*Repository).getCommitFromBatchReader: commit, err := CommitFromReader(repo, id, io.LimitReader(rd, size))
/home/aot/src/gitea/modules/git/repo_commit_nogogit.go:75 (0xff329b)
	(*Repository).getCommit: return repo.getCommitFromBatchReader(rd, id)
/home/aot/src/gitea/modules/git/repo_commit.go:37 (0xfe57c4)
	(*Repository).GetCommit: return repo.getCommit(id)
/home/aot/src/gitea/modules/git/repo_commit.go:46 (0xfe586d)
	(*Repository).GetBranchCommit: return repo.GetCommit(commitID)
/home/aot/src/gitea/modules/context/repo.go:945 (0x1ae41a4)
	RepoRefByType.func1: ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(refName)
/home/aot/src/gitea/modules/web/wrap_convert.go:55 (0x1eea8f3)
	convertHandler.func4: deferrable = t(ctx)
/home/aot/src/gitea/modules/web/wrap.go:41 (0x1ee8ec4)
	wrapInternal.func1: done, deferrable := handler(resp, req, others...)
/usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae)
	HandlerFunc.ServeHTTP: f(w, r)
/home/aot/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:442 (0x1ac3835)
	(*Mux).routeHTTP: h.ServeHTTP(w, r)
/usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae)
	HandlerFunc.ServeHTTP: f(w, r)
/home/aot/src/gitea/modules/web/wrap.go:63 (0x1ee9308)
	Middle.func1.1: next.ServeHTTP(ctx.Resp, ctx.Req)
/usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae)
	HandlerFunc.ServeHTTP: f(w, r)
/home/aot/src/gitea/modules/web/wrap.go:63 (0x1ee9308)
	Middle.func1.1: next.ServeHTTP(ctx.Resp, ctx.Req)
/usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae)
	HandlerFunc.ServeHTTP: f(w, r)
/home/aot/src/gitea/modules/web/wrap.go:63 (0x1ee9308)
	Middle.func1.1: next.ServeHTTP(ctx.Resp, ctx.Req)
/usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae)
	HandlerFunc.ServeHTTP: f(w, r)
/home/aot/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/middleware/get_head.go:37 (0x1fafd6d)
	GetHead.func1: next.ServeHTTP(w, r)
/usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae)
	HandlerFunc.ServeHTTP: f(w, r)
/home/aot/src/gitea/modules/web/wrap.go:63 (0x1ee9308)
	Middle.func1.1: next.ServeHTTP(ctx.Resp, ctx.Req)
/usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae)
	HandlerFunc.ServeHTTP: f(w, r)
/home/aot/src/gitea/modules/context/context.go:806 (0x1ad7dfa)
	Contexter.func1.1: next.ServeHTTP(ctx.Resp, ctx.Req)
/usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae)
	HandlerFunc.ServeHTTP: f(w, r)
/home/aot/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:71 (0x1ac15f4)
	(*Mux).ServeHTTP: mx.handler.ServeHTTP(w, r)
/home/aot/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:314 (0x1ac2ffb)
	(*Mux).Mount.func1: handler.ServeHTTP(w, r)
/usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae)
	HandlerFunc.ServeHTTP: f(w, r)
/home/aot/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:442 (0x1ac3835)
	(*Mux).routeHTTP: h.ServeHTTP(w, r)
/usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae)
	HandlerFunc.ServeHTTP: f(w, r)
/home/aot/src/gitea/routers/web/base.go:175 (0x218c6d1)
	Recovery.func1.1: next.ServeHTTP(w, req)
/usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae)
	HandlerFunc.ServeHTTP: f(w, r)
/home/aot/go/pkg/mod/gitea.com/go-chi/session@v0.0.0-20211218221615-e3605d8b28b8/session.go:257 (0x125d3ea)
	Sessioner.func1.1: next.ServeHTTP(w, req)
/usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae)
	HandlerFunc.ServeHTTP: f(w, r)
/home/aot/src/gitea/modules/web/wrap.go:110 (0x1ee9cc8)
	WrapWithPrefix.func1.1: next.ServeHTTP(resp, req)
/usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae)
	HandlerFunc.ServeHTTP: f(w, r)
/home/aot/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:71 (0x1ac15f4)
	(*Mux).ServeHTTP: mx.handler.ServeHTTP(w, r)
/home/aot/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:314 (0x1ac2ffb)
	(*Mux).Mount.func1: handler.ServeHTTP(w, r)
/usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae)
	HandlerFunc.ServeHTTP: f(w, r)
/home/aot/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:442 (0x1ac3835)
	(*Mux).routeHTTP: h.ServeHTTP(w, r)
/usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae)
	HandlerFunc.ServeHTTP: f(w, r)
/home/aot/src/gitea/routers/common/middleware.go:79 (0x1fb53a2)
	Middlewares.func2.1: next.ServeHTTP(resp, req)
/usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae)
	HandlerFunc.ServeHTTP: f(w, r)
/home/aot/src/gitea/modules/web/routing/logger_manager.go:123 (0x1ee4bd3)
	(*requestRecordsManager).handler.func1: next.ServeHTTP(w, req)
/usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae)
	HandlerFunc.ServeHTTP: f(w, r)
/home/aot/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/middleware/strip.go:30 (0x1fb2c38)
	StripSlashes.func1: next.ServeHTTP(w, r)
/usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae)
	HandlerFunc.ServeHTTP: f(w, r)
/home/aot/go/pkg/mod/github.com/chi-middleware/proxy@v1.1.1/middleware.go:37 (0x1faf3d6)
	ForwardedHeaders.func1.1: h.ServeHTTP(w, r)
/usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae)
	HandlerFunc.ServeHTTP: f(w, r)
/home/aot/src/gitea/routers/common/middleware.go:32 (0x1fb51f1)
	Middlewares.func1.1: next.ServeHTTP(context.NewResponse(resp), req.WithContext(ctx))
/usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae)
	HandlerFunc.ServeHTTP: f(w, r)
/home/aot/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:88 (0x1ac15af)
	(*Mux).ServeHTTP: mx.handler.ServeHTTP(w, r)
/home/aot/src/gitea/modules/web/route.go:200 (0x1ee82ed)
	(*Route).ServeHTTP: r.R.ServeHTTP(w, req)
/usr/lib/go-1.19/src/net/http/server.go:2947 (0x9530ab)
	serverHandler.ServeHTTP: handler.ServeHTTP(rw, req)
/usr/lib/go-1.19/src/net/http/server.go:1991 (0x94e786)
	(*conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req)
/usr/lib/go-1.19/src/runtime/asm_amd64.s:1594 (0x4770e0)
	goexit: BYTE	$0x90	// NOP

because emailStart == 0 in modules/git/signature_nogogit.go:54

Gitea Version

e77b76425e

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

No response

Screenshots

No response

Git Version

2.35.1

Operating System

debian testing

How are you running Gitea?

Built from source.

Database

SQLite

Originally created by @ghost on GitHub (Nov 22, 2022). ### Description Not sure how it happened, I have commits without an author name in a repository. ``` commit ea187914379a3137a46784c716307a2844dbe744 Author: <example@example.com> Date: Thu Mar 27 12:51:29 2008 +0100 ``` Pushing this repository will lead to a 500 error when visiting the repository page on gitea, due to the following exception : ``` 2022/11/22 17:58:15 routers/web/base.go:135:1() [E] [637cffa7] PANIC: runtime error: slice bounds out of range [:-1] /usr/lib/go-1.19/src/runtime/panic.go:139 (0x4404be) goPanicSliceAcap: panic(boundsError{x: int64(x), signed: true, y: y, code: boundsSliceAcap}) /home/aot/src/gitea/modules/git/signature_nogogit.go:54 (0x100bc3c) newSignatureFromCommitline: sig.Name = string(line[:emailStart-1]) /home/aot/src/gitea/modules/git/signature_nogogit.go:33 (0xfbfa5c) (*Signature).Decode: sig, _ := newSignatureFromCommitline(b) /home/aot/src/gitea/modules/git/commit_reader.go:82 (0xfbfa45) CommitFromReader: commit.Author.Decode(data) /home/aot/src/gitea/modules/git/repo_commit_nogogit.go:117 (0xff34c8) (*Repository).getCommitFromBatchReader: commit, err := CommitFromReader(repo, id, io.LimitReader(rd, size)) /home/aot/src/gitea/modules/git/repo_commit_nogogit.go:75 (0xff329b) (*Repository).getCommit: return repo.getCommitFromBatchReader(rd, id) /home/aot/src/gitea/modules/git/repo_commit.go:37 (0xfe57c4) (*Repository).GetCommit: return repo.getCommit(id) /home/aot/src/gitea/modules/git/repo_commit.go:46 (0xfe586d) (*Repository).GetBranchCommit: return repo.GetCommit(commitID) /home/aot/src/gitea/modules/context/repo.go:945 (0x1ae41a4) RepoRefByType.func1: ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(refName) /home/aot/src/gitea/modules/web/wrap_convert.go:55 (0x1eea8f3) convertHandler.func4: deferrable = t(ctx) /home/aot/src/gitea/modules/web/wrap.go:41 (0x1ee8ec4) wrapInternal.func1: done, deferrable := handler(resp, req, others...) /usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae) HandlerFunc.ServeHTTP: f(w, r) /home/aot/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:442 (0x1ac3835) (*Mux).routeHTTP: h.ServeHTTP(w, r) /usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae) HandlerFunc.ServeHTTP: f(w, r) /home/aot/src/gitea/modules/web/wrap.go:63 (0x1ee9308) Middle.func1.1: next.ServeHTTP(ctx.Resp, ctx.Req) /usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae) HandlerFunc.ServeHTTP: f(w, r) /home/aot/src/gitea/modules/web/wrap.go:63 (0x1ee9308) Middle.func1.1: next.ServeHTTP(ctx.Resp, ctx.Req) /usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae) HandlerFunc.ServeHTTP: f(w, r) /home/aot/src/gitea/modules/web/wrap.go:63 (0x1ee9308) Middle.func1.1: next.ServeHTTP(ctx.Resp, ctx.Req) /usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae) HandlerFunc.ServeHTTP: f(w, r) /home/aot/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/middleware/get_head.go:37 (0x1fafd6d) GetHead.func1: next.ServeHTTP(w, r) /usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae) HandlerFunc.ServeHTTP: f(w, r) /home/aot/src/gitea/modules/web/wrap.go:63 (0x1ee9308) Middle.func1.1: next.ServeHTTP(ctx.Resp, ctx.Req) /usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae) HandlerFunc.ServeHTTP: f(w, r) /home/aot/src/gitea/modules/context/context.go:806 (0x1ad7dfa) Contexter.func1.1: next.ServeHTTP(ctx.Resp, ctx.Req) /usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae) HandlerFunc.ServeHTTP: f(w, r) /home/aot/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:71 (0x1ac15f4) (*Mux).ServeHTTP: mx.handler.ServeHTTP(w, r) /home/aot/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:314 (0x1ac2ffb) (*Mux).Mount.func1: handler.ServeHTTP(w, r) /usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae) HandlerFunc.ServeHTTP: f(w, r) /home/aot/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:442 (0x1ac3835) (*Mux).routeHTTP: h.ServeHTTP(w, r) /usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae) HandlerFunc.ServeHTTP: f(w, r) /home/aot/src/gitea/routers/web/base.go:175 (0x218c6d1) Recovery.func1.1: next.ServeHTTP(w, req) /usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae) HandlerFunc.ServeHTTP: f(w, r) /home/aot/go/pkg/mod/gitea.com/go-chi/session@v0.0.0-20211218221615-e3605d8b28b8/session.go:257 (0x125d3ea) Sessioner.func1.1: next.ServeHTTP(w, req) /usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae) HandlerFunc.ServeHTTP: f(w, r) /home/aot/src/gitea/modules/web/wrap.go:110 (0x1ee9cc8) WrapWithPrefix.func1.1: next.ServeHTTP(resp, req) /usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae) HandlerFunc.ServeHTTP: f(w, r) /home/aot/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:71 (0x1ac15f4) (*Mux).ServeHTTP: mx.handler.ServeHTTP(w, r) /home/aot/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:314 (0x1ac2ffb) (*Mux).Mount.func1: handler.ServeHTTP(w, r) /usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae) HandlerFunc.ServeHTTP: f(w, r) /home/aot/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:442 (0x1ac3835) (*Mux).routeHTTP: h.ServeHTTP(w, r) /usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae) HandlerFunc.ServeHTTP: f(w, r) /home/aot/src/gitea/routers/common/middleware.go:79 (0x1fb53a2) Middlewares.func2.1: next.ServeHTTP(resp, req) /usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae) HandlerFunc.ServeHTTP: f(w, r) /home/aot/src/gitea/modules/web/routing/logger_manager.go:123 (0x1ee4bd3) (*requestRecordsManager).handler.func1: next.ServeHTTP(w, req) /usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae) HandlerFunc.ServeHTTP: f(w, r) /home/aot/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/middleware/strip.go:30 (0x1fb2c38) StripSlashes.func1: next.ServeHTTP(w, r) /usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae) HandlerFunc.ServeHTTP: f(w, r) /home/aot/go/pkg/mod/github.com/chi-middleware/proxy@v1.1.1/middleware.go:37 (0x1faf3d6) ForwardedHeaders.func1.1: h.ServeHTTP(w, r) /usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae) HandlerFunc.ServeHTTP: f(w, r) /home/aot/src/gitea/routers/common/middleware.go:32 (0x1fb51f1) Middlewares.func1.1: next.ServeHTTP(context.NewResponse(resp), req.WithContext(ctx)) /usr/lib/go-1.19/src/net/http/server.go:2109 (0x94fcae) HandlerFunc.ServeHTTP: f(w, r) /home/aot/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.7/mux.go:88 (0x1ac15af) (*Mux).ServeHTTP: mx.handler.ServeHTTP(w, r) /home/aot/src/gitea/modules/web/route.go:200 (0x1ee82ed) (*Route).ServeHTTP: r.R.ServeHTTP(w, req) /usr/lib/go-1.19/src/net/http/server.go:2947 (0x9530ab) serverHandler.ServeHTTP: handler.ServeHTTP(rw, req) /usr/lib/go-1.19/src/net/http/server.go:1991 (0x94e786) (*conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req) /usr/lib/go-1.19/src/runtime/asm_amd64.s:1594 (0x4770e0) goexit: BYTE $0x90 // NOP ``` because emailStart == 0 in modules/git/signature_nogogit.go:54 ### Gitea Version e77b76425e5ae205d6db2c78ab7b31fbc1b186a6 ### Can you reproduce the bug on the Gitea demo site? Yes ### Log Gist _No response_ ### Screenshots _No response_ ### Git Version 2.35.1 ### Operating System debian testing ### How are you running Gitea? Built from source. ### Database SQLite
GiteaMirror added the type/bug label 2025-11-02 08:51:58 -06:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#9872