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

runtime error: index out of range [XXX] with length YYY #1019

Open
1 task done
gandarez opened this issue Oct 29, 2024 · 3 comments
Open
1 task done

runtime error: index out of range [XXX] with length YYY #1019

gandarez opened this issue Oct 29, 2024 · 3 comments
Labels

Comments

@gandarez
Copy link
Contributor

gandarez commented Oct 29, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

At wakatime-cli we heavily use Chroma to find file dependencies and guess their programming languages. We also support parsing C files and extract this kind of information. Here's the function we get panic and the stack trace:

goroutine 1 [running]:
runtime/debug.Stack()
/opt/hostedtoolcache/go/1.22.5/x64/src/runtime/debug/stack.go:24 +0x5e
github.com/wakatime/wakatime-cli/cmd.runCmd.func1()
/home/runner/work/wakatime-cli/wakatime-cli/cmd/run.go:297 +0x148
panic({0xafc7a0?, 0xc0a6722c48?})
/opt/hostedtoolcache/go/1.22.5/x64/src/runtime/panic.go:770 +0x132
github.com/dlclark/regexp2.(*runner).backtrack(0xc00000003b?)
/home/runner/go/pkg/mod/github.com/dlclark/[email protected]/runner.go:1032 +0x1d5
github.com/dlclark/regexp2.(*runner).execute(0xc0002169a0)
/home/runner/go/pkg/mod/github.com/dlclark/[email protected]/runner.go:903 +0x36f9
github.com/dlclark/regexp2.(*runner).scan(0xc0002169a0, {0xc03cebe000?, 0xc000259430?, 0x419f05?}, 0xa57820?, 0x0, 0x2?)
/home/runner/go/pkg/mod/github.com/dlclark/[email protected]/runner.go:143 +0x2c6
github.com/dlclark/regexp2.(*Regexp).run(0xc000279080, 0x0, 0xd2be762, {0xc03cebe000, 0x10bbeda3, 0x10bbf000})
/home/runner/go/pkg/mod/github.com/dlclark/[email protected]/runner.go:90 +0xf9
github.com/dlclark/regexp2.(*Regexp).FindRunesMatchStartingAt(...)
/home/runner/go/pkg/mod/github.com/dlclark/[email protected]/regexp.go:206
github.com/alecthomas/chroma/v2.matchRules({0xc03cebe000, 0x10bbeda3, 0x10bbf000}, 0xd2be762, {0xc00011e400, 0x20, 0x4707d2?})
/home/runner/go/pkg/mod/github.com/alecthomas/chroma/[email protected]/regexp.go:452 +0xbd
github.com/alecthomas/chroma/v2.(*LexerState).Iterator(0xc000000480)
/home/runner/go/pkg/mod/github.com/alecthomas/chroma/[email protected]/regexp.go:212 +0x225
github.com/alecthomas/chroma/v2.Iterator.Tokens(0xc00026c020)
/home/runner/go/pkg/mod/github.com/alecthomas/chroma/[email protected]/iterator.go:15 +0x46
github.com/wakatime/wakatime-cli/pkg/deps.(*ParserC).Parse(0xc0001407e0, {0x7ffd80171f88, 0x2d})
/home/runner/work/wakatime-cli/wakatime-cli/pkg/deps/c.go:67 +0x24e
github.com/wakatime/wakatime-cli/pkg/deps.Detect({0x7ffd80171f88, 0x2d}, 0x0?)
/home/runner/work/wakatime-cli/wakatime-cli/pkg/deps/deps.go:129 +0x3e8
github.com/wakatime/wakatime-cli/cmd/heartbeat.initHandleOptions.WithDetection.func8.1({0xc000495b80, 0x1, 0x1})
/home/runner/work/wakatime-cli/wakatime-cli/pkg/deps/deps.go:68 +0x2a5
github.com/wakatime/wakatime-cli/cmd/heartbeat.initHandleOptions.WithDetection.func7.1({0xc000495b80, 0x1, 0x1})
/home/runner/work/wakatime-cli/wakatime-cli/pkg/language/language.go:54 +0x36c
github.com/wakatime/wakatime-cli/cmd/heartbeat.initHandleOptions.WithDetection.func6.1({0xc000495b80, 0x1, 0x1})
/home/runner/work/wakatime-cli/wakatime-cli/pkg/filestats/filestats.go:73 +0x546
github.com/wakatime/wakatime-cli/cmd/heartbeat.initHandleOptions.WithReplacing.func5.1({0xc000495b80, 0x1, 0x1})
/home/runner/work/wakatime-cli/wakatime-cli/pkg/apikey/apikey.go:44 +0x1cb
github.com/wakatime/wakatime-cli/cmd/heartbeat.initHandleOptions.WithDetection.func4.1({0xc0004957c0, 0x1, 0x0?})
/home/runner/work/wakatime-cli/wakatime-cli/pkg/remote/remote.go:112 +0x93c
github.com/wakatime/wakatime-cli/cmd/heartbeat.initHandleOptions.WithFiltering.func3.1({0xc0004f3a40, 0x1, 0x4c5c9b?})
/home/runner/work/wakatime-cli/wakatime-cli/pkg/filter/filter.go:41 +0x2d0
github.com/wakatime/wakatime-cli/cmd/heartbeat.initHandleOptions.WithEntityModifier.func2.1({0xc0004f3a40, 0x1, 0x1})
/home/runner/work/wakatime-cli/wakatime-cli/pkg/heartbeat/entity_modify.go:28 +0x302
github.com/wakatime/wakatime-cli/cmd/heartbeat.initHandleOptions.WithFormatting.func1.1({0xc0004f3a40, 0x1, 0x1})
/home/runner/work/wakatime-cli/wakatime-cli/pkg/heartbeat/format.go:32 +0x28e
github.com/wakatime/wakatime-cli/cmd/heartbeat.SendHeartbeats.NewHandle.func4({0xc0004f3a40, 0x1, 0x1})
/home/runner/work/wakatime-cli/wakatime-cli/pkg/heartbeat/heartbeat.go:175 +0xc8
github.com/wakatime/wakatime-cli/cmd/heartbeat.SendHeartbeats(0xc0006828c0, {0xc000174bd0, 0x2f})
/home/runner/work/wakatime-cli/wakatime-cli/cmd/heartbeat/heartbeat.go:140 +0x850
github.com/wakatime/wakatime-cli/cmd/heartbeat.Run(0xc0006828c0)
/home/runner/work/wakatime-cli/wakatime-cli/cmd/heartbeat/heartbeat.go:39 +0xc5
github.com/wakatime/wakatime-cli/cmd.runCmd(0xc0006828c0, 0x0, 0x0, 0xd3d8f0)
/home/runner/work/wakatime-cli/wakatime-cli/cmd/run.go:315 +0x127
github.com/wakatime/wakatime-cli/cmd.RunCmdWithOfflineSync(0xc0006828c0, 0x0, 0x0, 0x0?)
/home/runner/work/wakatime-cli/wakatime-cli/cmd/run.go:272 +0x25
github.com/wakatime/wakatime-cli/cmd.RunE(0xc0000e4308, 0xc0006828c0)
/home/runner/work/wakatime-cli/wakatime-cli/cmd/run.go:135 +0x945
github.com/wakatime/wakatime-cli/cmd.NewRootCMD.func1(0xc00011f000?, {0xb35a60?, 0x4?, 0xb35a64?})
/home/runner/work/wakatime-cli/wakatime-cli/cmd/root.go:32 +0x17
github.com/spf13/cobra.(*Command).execute(0xc0000e4308, {0xc000034100, 0xe, 0xe})
/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:940 +0x882
github.com/spf13/cobra.(*Command).ExecuteC(0xc0000e4308)
/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:1068 +0x3a5
github.com/spf13/cobra.(*Command).Execute(...)
/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:992
github.com/wakatime/wakatime-cli/cmd.Execute()
/home/runner/work/wakatime-cli/wakatime-cli/cmd/root.go:301 +0x18
main.main()
/home/runner/work/wakatime-cli/wakatime-cli/main.go:6 +0xf

The error is always index out of range but it changes the length according to the size of the file, I guess.

To Reproduce

I do not have access to the file's content to reproduce the error because they run in the user's machine and it's protected by privacy.

@gandarez gandarez added the bug label Oct 29, 2024
@gandarez
Copy link
Contributor Author

gandarez commented Jan 5, 2025

nobody to help me? It's still happening in 2.14.0.

@alecthomas
Copy link
Owner

alecthomas commented Jan 5, 2025

Provide a way to reproduce it, or even better, send a PR.

@gandarez
Copy link
Contributor Author

gandarez commented Jan 9, 2025

@alecthomas this is a bug in the regexp2 library dlclark/regexp2#37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants