fix #6949: prevent RangeError when using large Buffers in axios requests#6961
Merged
jasonsaayman merged 1 commit intoaxios:v1.xfrom Jul 15, 2025
Merged
Conversation
Contributor
|
Hi, @manishsahanidev! This PR has been published in v1.11.0 release. Thank you for your contribution ❤️! |
This was referenced Oct 27, 2025
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.
Description
This PR fixes a critical RangeError that occurs when using large Buffers (>100-200MB) as request data in axios. The error was caused by calling
Object.keys()on Buffer instances during configuration merging, which attempts to enumerate every byte as a key.Problem
When axios processes large Buffer data, several utility functions would call
Object.keys()on the Buffer:Error:
RangeError: Invalid array lengthwhen Buffer size exceeds ~100-200MBSolution
Added Buffer checks to prevent
Object.keys()from being called on Buffer instances in:isEmptyObject()- Returnsfalsefor all Buffers (not empty objects)forEach()- Skips iteration for BuffersfindKey()- Returnsnullfor BufferstoJSONObject()- Returns Buffer as-is without processingChanges Made
1. Enhanced
isEmptyObjectfunction2. Enhanced
forEachfunction3. Enhanced
findKeyfunction4. Enhanced
toJSONObjectfunctionTest Coverage
Added comprehensive tests in
test/unit/utils/utils.js:Reproduction Case
Before (throws RangeError):
After (works correctly):
Backward Compatibility
Impact
This fix enables axios to handle large file uploads and binary data processing in Node.js environments without crashes, which is essential for:
Testing
Closes #[#6949]