Skip to content

Fix panic in blame view when a file has only a single commit#36230

Merged
wxiaoguang merged 1 commit intogo-gitea:mainfrom
0xMax42:fix/blame-view
Dec 23, 2025
Merged

Fix panic in blame view when a file has only a single commit#36230
wxiaoguang merged 1 commit intogo-gitea:mainfrom
0xMax42:fix/blame-view

Conversation

@0xMax42
Copy link
Copy Markdown
Contributor

@0xMax42 0xMax42 commented Dec 22, 2025

This PR fixes a panic in the repository blame view that occurs when rendering files
whose blame history consists of only a single commit.

In this case, the number of rendered blame rows can exceed the number of
highlighted lines returned by the syntax highlighter. The existing bounds check
incorrectly used len(rows), which may be greater than len(unsafeLines),
leading to an out-of-range access on unsafeLines and a runtime panic.

The fix changes the bounds check to use len(unsafeLines) instead, ensuring we
never index past the available highlighted lines.

This issue is reproducible with files that:

  • were introduced in exactly one commit, and
  • are accessed via the blame view (e.g. /blame/commit/<sha>/file).

The change is minimal, safe, and does not affect normal blame rendering.


Example error:

2025/12/22 02:35:31 HTTPRequest [W] router: failed    GET /actions/deb-changelog-action/blame/commit/1239d674128fe38b284802f4e97c70068116fd52/CHANGELOG.md for XXX.XXX.XXX.XXX:0, panic in 34.8ms @ repo/blame.go:44(repo.RefBlame), err=runtime error: index out of range [61] with length 61
2025/12/22 02:35:31 routers/common/errpage.go:25:RenderPanicErrorPage() [E] PANIC: runtime error: index out of range [61] with length 61
/usr/local/go/src/runtime/panic.go:783 (0x4860b1)
/go/src/code.gitea.io/gitea/modules/web/routing/logger_manager.go:116 (0x19b8a84)
/usr/local/go/src/runtime/panic.go:783 (0x4860b1)
/usr/local/go/src/runtime/panic.go:115 (0x44a1b3)
/go/src/code.gitea.io/gitea/routers/web/repo/blame.go:275 (0x2aaa01a)
/go/src/code.gitea.io/gitea/routers/web/repo/blame.go:97 (0x2aa8a08)
[...]

Introduced with PR #36157

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Dec 22, 2025
@github-actions github-actions bot added the modifies/go Pull requests that update Go code label Dec 22, 2025
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Dec 22, 2025
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Dec 23, 2025
@wxiaoguang wxiaoguang merged commit 9571519 into go-gitea:main Dec 23, 2025
24 checks passed
@GiteaBot GiteaBot added this to the 1.26.0 milestone Dec 23, 2025
@0xMax42 0xMax42 deleted the fix/blame-view branch December 23, 2025 16:19
zjjhot added a commit to zjjhot/gitea that referenced this pull request Dec 26, 2025
* giteaofficial/main:
  Fix panic when get editor config file (go-gitea#36241)
  Refactor compare router param parse (go-gitea#36105)
  [skip ci] Updated translations via Crowdin
  Use flatten translation keys (go-gitea#36225)
  Replace CSRF cookie with `CrossOriginProtection` (go-gitea#36183)
  Remove fomantic form module (go-gitea#36222)
  Fix panic in blame view when a file has only a single commit (go-gitea#36230)
  fix: spelling error in migrate-storage cmd utility (go-gitea#36226)

# Conflicts:
#	templates/user/settings/security/twofa.tmpl
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Mar 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/go Pull requests that update Go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants