go-gitea / gitea

Git with a cup of tea! Painless self-hosted all-in-one software development service, including Git hosting, code review, team collaboration, package registry and CI/CD
https://gitea.com
MIT License
44.6k stars 5.45k forks source link

Panic in git blame #12440

Closed sbrl closed 3 years ago

sbrl commented 4 years ago

Description

When accessing a specific git blame, I get a HTTP error 500. I noticed this because the Googlebot was indexing my git server, and caught it. The specific URL is as follows: https://git.starbeamrainbowlabs.com/sbrl-github/Pepperminty-Wiki/blame/commit/edba3b9bf3af109935a8ec7dc76914611b0dcb2f/php_error.php

This particular repo is a backup mirror of https://github.com/sbrl/Pepperminty-Wiki, so the specific URL on GitHub is as follows: https://github.com/sbrl/Pepperminty-Wiki/blame/edba3b9bf3af109935a8ec7dc76914611b0dcb2f/php_error.php

Just thought I'd report, since it seems like a crash that might need fixing. Feel free to close this if it can't be debugged :-)

Screenshots

image

Stack trace from logs:

2020/08/06 02:04:32 ...les/context/panic.go:35:1() [E] PANIC:: runtime error: invalid memory address or nil pointer dereference
    /usr/local/go/src/runtime/panic.go:212 (0x452e59)
    /usr/local/go/src/runtime/signal_unix.go:695 (0x452ca8)
    /go/src/code.gitea.io/gitea/modules/git/blame.go:70 (0x9f9e74)
    /go/src/code.gitea.io/gitea/routers/repo/blame.go:160 (0x19a223b)
    /usr/local/go/src/reflect/value.go:460 (0x49cc3a)
    /usr/local/go/src/reflect/value.go:321 (0x49c143)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/inject/inject.go:177 (0xc2861b)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/inject/inject.go:137 (0xc27ff9)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/context.go:121 (0xc43548)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/context.go:112 (0x125dd74)
    /go/src/code.gitea.io/gitea/modules/context/repo.go:797 (0x125dd5d)
    /usr/local/go/src/reflect/value.go:460 (0x49cc3a)
    /usr/local/go/src/reflect/value.go:321 (0x49c143)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/inject/inject.go:177 (0xc2861b)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/inject/inject.go:137 (0xc27ff9)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/context.go:121 (0xc43548)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/context.go:112 (0x125c45f)
    /go/src/code.gitea.io/gitea/modules/context/repo.go:579 (0x125c448)
    /usr/local/go/src/reflect/value.go:460 (0x49cc3a)
    /usr/local/go/src/reflect/value.go:321 (0x49c143)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/inject/inject.go:177 (0xc2861b)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/inject/inject.go:137 (0xc27ff9)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/context.go:121 (0xc43548)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/context.go:112 (0x1259d54)
    /go/src/code.gitea.io/gitea/modules/context/panic.go:39 (0x1259d45)
    /usr/local/go/src/reflect/value.go:460 (0x49cc3a)
    /usr/local/go/src/reflect/value.go:321 (0x49c143)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/inject/inject.go:177 (0xc2861b)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/inject/inject.go:137 (0xc27ff9)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/context.go:121 (0xc43548)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/context.go:112 (0x1211935)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/session/session.go:192 (0x1211920)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/context.go:79 (0xc433f0)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/inject/inject.go:157 (0xc28347)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/inject/inject.go:135 (0xc280e8)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/context.go:121 (0xc43548)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/context.go:112 (0x1b497c7)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/gzip/gzip.go:139 (0x1b497ba)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/context.go:79 (0xc433f0)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/inject/inject.go:157 (0xc28347)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/inject/inject.go:135 (0xc280e8)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/context.go:121 (0xc43548)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/context.go:112 (0xc54975)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/recovery.go:161 (0xc54968)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/logger.go:40 (0xc46fb3)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/inject/inject.go:157 (0xc28347)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/inject/inject.go:135 (0xc280e8)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/context.go:121 (0xc43548)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/context.go:112 (0xc53ca0)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/logger.go:52 (0xc53c8b)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/logger.go:40 (0xc46fb3)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/inject/inject.go:157 (0xc28347)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/inject/inject.go:135 (0xc280e8)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/context.go:121 (0xc43548)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/router.go:187 (0xc55b86)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/router.go:303 (0xc4f585)
    /go/src/code.gitea.io/gitea/vendor/gitea.com/macaron/macaron/macaron.go:218 (0xc4830a)
    /go/src/code.gitea.io/gitea/vendor/github.com/gorilla/context/context.go:141 (0xeba293)
    /usr/local/go/src/net/http/server.go:2041 (0x750943)
    /usr/local/go/src/net/http/server.go:2836 (0x753cd2)
    /usr/local/go/src/net/http/server.go:1924 (0x74f73b)
    /usr/local/go/src/runtime/asm_amd64.s:1373 (0x46f030)
stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. I am here to help clear issues left open even if solved or waiting for more insight. This issue will be closed if no further activity occurs during the next 2 weeks. If the issue is still valid just add a comment to keep it alive. Thank you for your contributions.

6543 commented 4 years ago

looks like at https://github.com/go-gitea/gitea/blob/20c2bdf86b96b279ccde2d222dff5c9fd2327703/modules/git/blame.go#L70

blamePart == nil <- witch should not be the case ...

6543 commented 4 years ago

bug in master (0e4f66312) too

https://try.gitea.io/abcKing/Pepperminty-Wiki/blame/commit/edba3b9bf3af109935a8ec7dc76914611b0dcb2f/php_error.php

42wim commented 4 years ago

Did some debugging on this. The issue is the scanner exits early on"bufio.Scanner: token too long".

https://golang.org/pkg/bufio/#Scanner

Scanning stops unrecoverably at EOF, the first I/O error, or a token too large to fit in the buffer. When a scan stops, the reader may have advanced arbitrarily far past the last token. Programs that need more control over error handling or large tokens, or must run sequential scans on a reader, should use bufio.Reader instead.

mappu commented 3 years ago

I'm seeing a lot of zombie git blame processes in my Gitea docker container, that I think are related to this issue:

https://gist.github.com/mappu/158ba6089f7f895554e4e9ec2be075f8 Output of ps fuxa

These files are all go-bindata -type files with very long lines. It seems like no Gitea process is reading their stdin any more so the process is never properly closed.

zeripath commented 3 years ago

What version of Gitea are you using?

mappu commented 3 years ago

Sorry, that was from a 1.11.4 server, and I can see it was already fixed in #11716 for 1.12. :+1:

AlrikG commented 3 years ago

Is it fixed or not? It is the last ticket in milestone 1.13

lafriks commented 3 years ago

This is not fixed yet

sbrl commented 3 years ago

Thanks, everyone for fixing this :D

zeripath commented 3 years ago

the fix in #13470 is not a complete fix - it could do with a little more finesse as I wrote on the PR itself.

zeripath commented 3 years ago

(not least because the 4096 byte stripper could end up splitting within a rune.)