From 53ba6e602b637802584d01210813ed2cb6872f20 Mon Sep 17 00:00:00 2001 From: tomaioo Date: Fri, 3 Jul 2026 11:22:01 -0700 Subject: [PATCH] refactor(app-expo): stack overflow risk in bytestobase64 due to large The `bytesToBase64` function spreads a `Uint8Array` chunk of size `0x8000` (32768) into `String.fromCharCode(...)`. Most JavaScript engines have a maximum argument count limit (typically ~65536 but often lower in practice), and spreading such a large array will cause a 'Maximum call stack size exceeded' error for files larger than ~32KB. Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com> --- packages/app-expo/src/lib/rag/auto-vectorize-book.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/app-expo/src/lib/rag/auto-vectorize-book.ts b/packages/app-expo/src/lib/rag/auto-vectorize-book.ts index dede9b9b..8c5d630a 100644 --- a/packages/app-expo/src/lib/rag/auto-vectorize-book.ts +++ b/packages/app-expo/src/lib/rag/auto-vectorize-book.ts @@ -19,12 +19,12 @@ export function getMobileVectorizeMimeType(format: string | undefined): string | } function bytesToBase64(bytes: Uint8Array): string { - const chunkSize = 0x8000; + const chunkSize = 0x1000; let binary = ""; for (let i = 0; i < bytes.length; i += chunkSize) { const chunk = bytes.subarray(i, i + chunkSize); - binary += String.fromCharCode(...chunk); + binary += Array.from(chunk, (b) => String.fromCharCode(b)).join(""); } return btoa(binary);