Skip to content

Guard git status parser against infinite loop on unknown entry#124

Open
grub-basket wants to merge 1 commit into
jorio:masterfrom
grub-basket:fix/status-parser-loop-guard
Open

Guard git status parser against infinite loop on unknown entry#124
grub-basket wants to merge 1 commit into
jorio:masterfrom
grub-basket:fix/status-parser-loop-guard

Conversation

@grub-basket

Copy link
Copy Markdown

Problem

In parseGitStatus, pos is only advanced from match.end() after a successful pattern lookup. On an unrecognized status ident the code hits continue without advancing pos, so it re-reads the same character forever — an infinite loop that also spams the warning log. Separately, a malformed record makes pattern.match(...) return None, crashing on match.end() with AttributeError.

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).

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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant