Skip to content

addPatterns silently drops all patterns after a line longer than 64KB #28

Closed

Description

@andrew

addPatterns reads the ignore file with bufio.NewScanner and never calls scanner.Buffer() or checks scanner.Err() (gitignore.go:440 on main). bufio.Scanner caps tokens at bufio.MaxScanTokenSize (64KB) by default; when a line exceeds that, Scan() returns false with bufio.ErrTooLong and the loop exits. Every pattern after the long line is silently discarded, so Match disagrees with git check-ignore for the remainder of the file and nothing is recorded in Errors().

Repro:

var b bytes.Buffer
b.WriteString(strings.Repeat("a", 70000))
b.WriteString("\n*.log\n")
m := &gitignore.Matcher{}
m.AddPatterns(b.Bytes(), "")
m.Match("app.log") // false; git check-ignore says ignored

Fix is either to raise the buffer (scanner.Buffer(nil, maxLine)) so the long line is parsed like git does, or keep the cap and record scanner.Err() in m.errors so the truncation is visible. The former keeps parity with git; the latter at least surfaces the divergence.

Activity

  1. added
    bug
    on Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions