fix(ai): cap native inline file size at 50 MB to prevent V8 OOM - #19867
Open
xxiaoxiong wants to merge 5 commits into
Open
fix(ai): cap native inline file size at 50 MB to prevent V8 OOM#19867xxiaoxiong wants to merge 5 commits into
xxiaoxiong wants to merge 5 commits into
Conversation
Refuses to allocate a base64 buffer for file parts whose on-disk size exceeds 50 MB. The previous behaviour inflated every native file by ~4/3 into the request JSON and exhausted main-process V8 heap on 8 GB machines, leading to SIGTRAP and whole-app exits. The cap is enforced before any read via FileManager.getMetadata (fileEntryId branch) or fs.stat (file:// URL branch). The file:// branch uses stat (follows symlinks) so symlink squatting cannot bypass the check by pointing at an over-cap target. On error, the size is treated as Infinity so the part is dropped instead of inlined. Closes CherryHQ#19706 Signed-off-by: xxiaoxiong <2482929840@qq.com>
Signed-off-by: xxiaoxiong <2482929840@qq.com>
Signed-off-by: xxiaoxiong <2482929840@qq.com>
…rt-sort Signed-off-by: xxiaoxiong <2482929840@qq.com>
Signed-off-by: xxiaoxiong <2482929840@qq.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR
Cap the size of files inlined as base64
data:URLs at 50 MB, enforced before the read to prevent V8 heap exhaustion and app crash (SIGTRAP) when users attach ~238 MB PDFs.Problem
fileProcessor.tsinlined every file as base64 without any size check. Base64 inflates a file by ~4/3; a 238 MB PDF becomes ~317 MB of base64, and withJSON.stringifyoverhead the main-process V8 heap (~2 GB on an 8 GB machine) is exhausted, leading to SIGTRAP and whole-app exits. This is #19706.Fix
Two pre-read size guards:
FileManager.getMetadata(size)called beforeread(encoding: base64)— prevents allocating the inflated base64 buffer for oversized files.fs.stat(absPath)called beforefsRead(encoding: base64)— same guard.statfollows symlinks, so symlink squatting cannot bypass the cap.On any error (missing entry, permission denied), size is treated as
Infinityso the part is degraded to a note, matching the existing failure path.Test coverage
Updated
fileProcessor.test.tsto mockFileManager.getMetadataand verify:nullwithout callingreadnull(existing behaviour preserved)References
NATIVE_INLINE_FILE_CAP_BYTESconstant is exported for future per-provider override (e.g. DashScope qwen-vl ≤ 10 MB raw inattachmentRouting.ts)