Quality: Stack overflow risk in bytesToBase64 due to large spread operator#520
Conversation
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>
|
中文:这个修复方向是对的,但目前只改了 English: The fix is in the right direction, but it only updates |
Summary
Quality: Stack overflow risk in bytesToBase64 due to large spread operator
Problem
Severity:
High| File:packages/app-expo/src/lib/rag/auto-vectorize-book.ts:L33The
bytesToBase64function spreads aUint8Arraychunk of size0x8000(32768) intoString.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.Solution
Replace the spread operator with a loop or use a smaller chunk size (e.g., 0x1000 or 4096). Alternatively, use
Array.from(chunk, b => String.fromCharCode(b)).join('')or a TextDecoder-based approach to avoid stack overflow.Changes
packages/app-expo/src/lib/rag/auto-vectorize-book.ts(modified)