From f99212f32e3986bda0fb9cb963dd7763f9832eea Mon Sep 17 00:00:00 2001 From: Pavan Kumar VH Date: Thu, 3 Sep 2026 15:04:28 +0530 Subject: [PATCH] Fix NaN handling in windowFileRead offset and limit The function didn't validate that offset and limit are finite numbers. If they were NaN or Infinity, Math.floor(NaN ?? 1) would return NaN, causing Math.max(1, NaN) to return NaN. Added Number.isFinite() checks to default to safe values for invalid numbers. --- common/src/util/file-read-limits.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/common/src/util/file-read-limits.ts b/common/src/util/file-read-limits.ts index 45bf201957..1295493654 100644 --- a/common/src/util/file-read-limits.ts +++ b/common/src/util/file-read-limits.ts @@ -22,9 +22,11 @@ export function windowFileRead( const lines = content.split('\n') if (lines.length > 1 && lines[lines.length - 1] === '') lines.pop() const totalLines = lines.length - const start = Math.max(1, Math.floor(offset ?? 1)) + const safeOffset = offset !== undefined && Number.isFinite(offset) ? offset : 1 + const safeLimit = limit !== undefined && Number.isFinite(limit) ? limit : MAX_READ_FILE_LINES + const start = Math.max(1, Math.floor(safeOffset)) const maxLines = Math.min( - Math.max(1, Math.floor(limit ?? MAX_READ_FILE_LINES)), + Math.max(1, Math.floor(safeLimit)), MAX_READ_FILE_LINES, )