Guard git status parser against infinite loop on unknown entry#124
Open
grub-basket wants to merge 1 commit into
Open
Guard git status parser against infinite loop on unknown entry#124grub-basket wants to merge 1 commit into
grub-basket wants to merge 1 commit into
Conversation
parseGitStatus advanced 'pos' only from a successful pattern match. On an unrecognized status ident it hit 'continue' without advancing, re-reading the same character forever and spamming warnings. A malformed record could also make pattern.match() return None, crashing on match.end(). Handle both cases by resyncing to the next NUL-terminated entry (or ending the loop if none remains).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In
parseGitStatus,posis only advanced frommatch.end()after a successful pattern lookup. On an unrecognized status ident the code hitscontinuewithout advancingpos, so it re-reads the same character forever — an infinite loop that also spams the warning log. Separately, a malformed record makespattern.match(...)returnNone, crashing onmatch.end()withAttributeError.Fix
Handle both cases: if the ident is unknown or the record doesn't match, log once and resync to the next NUL-terminated entry (
stdout.find("\x00", pos) + 1), or end the loop if no NUL remains. This is a defensive guard — a single unexpected entry can no longer wedge the status parser.Prepared with Claude Fable 5 (Low effort mode).