Fix infinite loop in LinuxPerfScriptEventParser on truncated sched_switch lines#2446
Open
brianrob wants to merge 1 commit into
Open
Fix infinite loop in LinuxPerfScriptEventParser on truncated sched_switch lines#2446brianrob wants to merge 1 commit into
brianrob wants to merge 1 commit into
Conversation
…itch lines ReadProcessNameUntilNextField loops until it finds the expected next field name (e.g. prev_pid/next_pid/pid). On malformed or truncated perf script input where that field name never appears, the loop never terminated, hanging the parser. OneFuzz fuzzing of the Linux perf script parser found 146 such hang inputs. Break out of the loop when the end of the stream is reached. Adds a regression test that parses a truncated sched_switch line and asserts parsing terminates. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 7c1dc14b-deed-412d-bdca-a44a5ac9bf9a
brianrob
marked this pull request as ready for review
July 23, 2026 00:01
leculver
approved these changes
Jul 23, 2026
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.
Summary
Fixes an infinite loop (parser hang) in
LinuxPerfScriptEventParserwhen parsing malformed or truncatedsched_switchlines.ReadProcessNameUntilNextFieldloops until it finds the expected next field name (e.g.prev_pid,next_pid,pid). If that field name never appears before the end of the stream — as happens with truncated/malformed perf script input — the loop never terminated and the parser hung indefinitely.Root cause
The
while (true)loop inReadProcessNameUntilNextFieldhad no end-of-stream termination condition. At EOF,FastStreamreturns a sentinel andReadFixedStringnever matches the target field name, so the loop spins forever appending spaces.Fix
Break out of the loop when
source.EndOfStreamis reached.How it was found
OneFuzz fuzzing of the Linux perf script parser produced 146 hang inputs (out of 155 recorded crashes). All 146 replayed as 30s timeouts before this change; with the fix all inputs terminate cleanly.
Test
Adds
LinuxPerfScriptEventParserTests.TruncatedSchedSwitchDoesNotHang, which parses a truncatedsched_switchline and asserts parsing terminates (fails via timeout if the infinite loop regresses). Passes on net462 and net8.0.