Skip to content

Opt-in size limit for ignore files read from disk #29

Closed

Description

@andrew

New and AddFromFile call os.ReadFile on each .gitignore, then compile every line into a pattern. Cost is linear in file size (roughly 2-3x the raw bytes once compiled), which is correct and matches git, but a caller walking many untrusted clones has no way to bound it short of statting every candidate file itself before constructing the matcher.

An opt-in ceiling would let such callers set a per-file cap without changing default behaviour:

m := gitignore.New(root, gitignore.MaxIgnoreFileSize(1<<20))

or a field on Matcher that AddFromFile consults. Files over the limit would be skipped with an entry in Errors(). Default (0 / unset) keeps current behaviour so parity with git is preserved unless the caller asks otherwise.

Related: #28 covers the separate case where a single long line inside the file truncates parsing.

Activity

  1. added
    enhancement
    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

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions