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

panic: error parsing regexp #436

Open
matmut7 opened this issue Nov 8, 2023 · 1 comment
Open

panic: error parsing regexp #436

matmut7 opened this issue Nov 8, 2023 · 1 comment

Comments

@matmut7
Copy link

matmut7 commented Nov 8, 2023

Describe the bug
With Talisman set up as a git hook, trying to commit a change containing a certain string can cause a regexp call to panic.

To be more precise, if a file contains git --diff, this test passes and a diff content line is treated like a diff header line. Now if the line is too long, this will panic because we created a regex with a repeat count that exceeds regexp's hard limit of 1000.

The error I get:

Talisman done in 3.003376ms
panic: regexp: Compile(`^diff --git a/(.{1001}) b/(.{1001})$`): error parsing regexp: invalid repeat count: `{1001}`

goroutine 1 [running]:
regexp.MustCompile({0xc00001af90, 0x24})
        /usr/lib/go/src/regexp/regexp.go:319 +0xb4
talisman/gitrepo.MatchGitDiffLine({0xc000121275, 0x7e2})
        /home/test/talisman/gitrepo/gitrepo.go:110 +0x1d9
talisman/gitrepo.GitRepo.GetDiffForStagedFiles({{0xc00001a124, 0x26}})
        /home/test/talisman/gitrepo/gitrepo.go:67 +0x22b
main.NewPreCommitHook()
        /home/test/talisman/cmd/pre_commit_hook.go:17 +0x25
main.run({0x0?, {0x9eed40?, 0xc5b060?}})
        /home/test/talisman/cmd/talisman.go:161 +0x365
main.main()
        /home/test/talisman/cmd/talisman.go:124 +0x252

To Reproduce
Take a repo with Talisman set up a pre-commit hook and then run this command to create a file as described above:

echo 'diff --git a/abc b/abc aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' > test.txt

Try to commit and see the panic message. If you delete one character from the previous line, Talisman runs fine.

@devthejo
Copy link

a workaround:
adding binary attr to .gitattributes files, eg:

/.yarn/releases/** binary
/.yarn/plugins/** binary

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

No branches or pull requests

2 participants