#1338·gitleaks

gitdiff report "parser" can cause an infinite wait on parser error

Author: groboclownCreated Feb 11, 2024Updated Aug 25, 2026
Labelsbughelp wanted

Describe the bug If the underlying git parser encounters a problem, then this causes the NewGitDiffCmd caller to never properly handle the error.

To Reproduce Steps to reproduce the behavior:

I encountered this when the Git diff command returned a header like:

@@ -231,18446744073709551615 +231,1 @@

(I have no idea why Git generates this, but it did.) The long number there looks like Git attempted to turn a "-1" into a uint64 value. This caused the parseRange function to generate an error, which then bubbled up to the parser.

The parser includes the code

go
if (err != nil) {
	return
}

This causes the error to be lost.

Additionally, the DetectGit seems to hang. The logic there contains:

go
select {
case gitdiffFile, open := <-diffFilesCh:
	if !open {
		diffFilesCh = nil
		break
	}

The !open block runs after the error is detected, but the block remains open, and the errCh never returns an error, which leaves the block listening forever.