feat(javascript): add configurable size guardrails#3539
Open
ayush00git wants to merge 8 commits intoapache:mainfrom
Open
feat(javascript): add configurable size guardrails#3539ayush00git wants to merge 8 commits intoapache:mainfrom
ayush00git wants to merge 8 commits intoapache:mainfrom
Conversation
Contributor
Author
|
Hii @chaokunyang @theweipeng |
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.
Why?
Untrusted binary/map/list lengths can trigger extremely large, uncontrolled memory allocations during deserialization. Relying on process-level memory limits is late-failing and risks heap exhaustion or OOM crashes from malicious payloads.
What does this PR do?
Adds configurable size guardrails to the Fory JavaScript library, checked immediately after the wire length is read to reject malformed payloads before any heavy allocation happens.
1. type.ts
Added optional
maxBinarySizeandmaxCollectionSizefields to the Config interface2. fory.ts
Added default limits (1,000,000 for collection, 64 MiB for binary) and added
checkCollectionSizeandcheckBinarySizevalidation methods.3. typedArray.ts
Injected guard checks into the codegen and runtime read paths before arrays, maps, and buffers are allocated.
4. sizeLimit.test.ts
Added a new test file validating limit boundaries, default thresholds, fallback typing, and polymorphism across all collection and binary read paths.
Related issues
Closes #3414
AI Contribution Checklist
yes/noyes, I included a completed AI Contribution Checklist in this PR description and the requiredAI Usage Disclosure.Does this PR introduce any user-facing change?
maxBinarySizeandmaxCollectionSizefields to the configuration.)Benchmark
N/A