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

ggshield crashes when scanning unmerged files during interactive merge #1002

Open
mherzberg opened this issue Nov 4, 2024 · 0 comments
Open
Labels
status:new This issue needs to be reviewed type:bug Something isn't working

Comments

@mherzberg
Copy link

Environment

  • ggshield version: 1.33.0
  • Operating system (Linux, macOS, Windows): Windows
  • Operating system version: 23H2
  • Python version: Unknown (self-contained Windows release)

Describe the bug

It appears that this chain of if-else-statements is missing the case where the status is U, meaning that the file is unmerged. This leads to a crash of ggshield when running the pre-commit scan when such a file is present. A file can reach this state during an interactive git merge. I don't believe this situation will occur during a typical pre-commit hook invocation, but it can occur during manual ggshield calls as shown below.

Steps to reproduce:

mkdir mergetest; cd mergetest
git init

git checkout -b b1
echo "" > "test file.txt"
git add "test file.txt"; git commit -m "Test"

git checkout -b b2
echo "foo" > "test file.txt"
git add "test file.txt"; git commit -m "Test"

git checkout b1
echo "bar" > "test file.txt"
git add "test file.txt"; git commit -m "Test"

git merge b2
ggshield secret scan pre-commit --verbose

Actual result:

Error: Can't parse header line :100644 000000 296458e 0000000 Utest file.txt: unknown status U

Traceback (most recent call last):
  File "ggshield\cmd\utils\common_decorators.py", line 18, in wrapper
  File "ggshield\cmd\secret\scan\precommit.py", line 83, in precommit_cmd
  File "ggshield\core\scan\commit.py", line 108, in from_merge
  File "ggshield\core\scan\commit_information.py", line 71, in from_staged
  File "ggshield\core\scan\commit_information.py", line 45, in from_patch_header
  File "ggshield\core\scan\commit_utils.py", line 195, in from_string
  File "ggshield\core\scan\commit_utils.py", line 195, in <listcomp>
  File "ggshield\core\scan\commit_utils.py", line 171, in from_string
ValueError: Can't parse header line :100644 000000 296458e 0000000 Utest file.txt: unknown status U

Expected result:

Scanning the relevant files for secrets as usual.

@mherzberg mherzberg added status:new This issue needs to be reviewed type:bug Something isn't working labels Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:new This issue needs to be reviewed type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant