Skip to content

Fix infinite loop in LinuxPerfScriptEventParser on truncated sched_switch lines#2446

Open
brianrob wants to merge 1 commit into
microsoft:mainfrom
brianrob:brianrob/linux-perfscript-hang
Open

Fix infinite loop in LinuxPerfScriptEventParser on truncated sched_switch lines#2446
brianrob wants to merge 1 commit into
microsoft:mainfrom
brianrob:brianrob/linux-perfscript-hang

Conversation

@brianrob

Copy link
Copy Markdown
Member

Summary

Fixes an infinite loop (parser hang) in LinuxPerfScriptEventParser when parsing malformed or truncated sched_switch lines.

ReadProcessNameUntilNextField loops 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 in ReadProcessNameUntilNextField had no end-of-stream termination condition. At EOF, FastStream returns a sentinel and ReadFixedString never matches the target field name, so the loop spins forever appending spaces.

Fix

Break out of the loop when source.EndOfStream is 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 truncated sched_switch line and asserts parsing terminates (fails via timeout if the infinite loop regresses). Passes on net462 and net8.0.

…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
brianrob marked this pull request as ready for review July 23, 2026 00:01
@brianrob
brianrob requested a review from a team as a code owner July 23, 2026 00:01
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.

2 participants