Skip to content

ggshield crashes when scanning unmerged files during interactive merge #1002

Open
@mherzberg

Description

@mherzberg

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status:newThis issue needs to be reviewedtype:bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions