From ff41a590ea3d89b98b8c300f3f68c10d625730e3 Mon Sep 17 00:00:00 2001 From: Harshal Patel <106813066+HarshalPatel1972@users.noreply.github.com> Date: Wed, 1 Jul 2026 00:30:38 +0530 Subject: [PATCH] pdh: prevent registry deadlocks via exponential buffer growth (#2438) Signed-off-by: Harshal Patel --- internal/pdh/registry/perflib.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/pdh/registry/perflib.go b/internal/pdh/registry/perflib.go index 6053eb15..424d82ae 100644 --- a/internal/pdh/registry/perflib.go +++ b/internal/pdh/registry/perflib.go @@ -243,9 +243,10 @@ func queryRawData(query string) ([]byte, error) { switch { case errors.Is(err, error(windows.ERROR_MORE_DATA)): - newBuffer := make([]byte, len(buffer)+16384) - copy(newBuffer, buffer) - buffer = newBuffer + // Exponential buffer growth prevents O(N) allocation spin-loops under heavy load. + // The previous copy() was removed because the buffer contents are + // incomplete/invalid and will be overwritten on the next API call. + buffer = make([]byte, len(buffer)*2) continue case errors.Is(err, error(windows.ERROR_BUSY)):