From 1f9b4bc0cc95d7e19e1fb2ded0e3e22305d0f445 Mon Sep 17 00:00:00 2001 From: Pavan Kumar VH Date: Thu, 3 Sep 2026 16:23:56 +0530 Subject: [PATCH] Fix NaN handling in min-heap index calculations The functions didn't validate that index is a finite number. If index was NaN or Infinity, Math.floor((NaN - 1) / 2) would return NaN, causing the heap operations to fail. Added Number.isFinite() checks to default to 0 for invalid numbers. --- common/src/util/min-heap.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/common/src/util/min-heap.ts b/common/src/util/min-heap.ts index fbf88117f1..240e2e2542 100644 --- a/common/src/util/min-heap.ts +++ b/common/src/util/min-heap.ts @@ -5,14 +5,17 @@ export class MinHeap { private heap: { item: T; score: number }[] = [] private getParentIndex(index: number): number { + if (!Number.isFinite(index)) return 0 return Math.floor((index - 1) / 2) } private getLeftChildIndex(index: number): number { + if (!Number.isFinite(index)) return 0 return 2 * index + 1 } private getRightChildIndex(index: number): number { + if (!Number.isFinite(index)) return 0 return 2 * index + 2 }