ArrayCoder can cause large memory usage when decoding bad data #1486
Labels
enhancement
New feature or improvement.
fixed/complete
This Bug is fixed or Enhancement is complete and published.
Describe the bug
When attempting to use
ArrayCoder
on data that isn't compatible, a potentially random amount of memory will be used because the array ofAnonymousCoder
instances are created before attempting to decode.Since the length is read first, this number could be anything. If it's not above JavaScript's
MAX_SAFE_INTEGER
, it'll be used and that manyAnonymousCoder
s are created.In our case, it was trying to create an array of 580,542,139,465,728 elements, and would always crash the process of course.
It is certainly an edge case, I don't expect many people to run into the issue. We are using ethers.js in a system that attempts to decode transactions without fully knowing the ABI, hence the possibility of the data not matching.
I've fixed the issue in our codebase by using a simple lazy array implementation, I would be happy to create a pull request.
Reproduction steps
Search Terms
ArrayCoder memory AnonymousCoder
The text was updated successfully, but these errors were encountered: