The vulnerability exists in the devalue library's deserialization logic, specifically in how it handles sparse arrays. The entry point for an attack is the exported parse function. This function calls an internal function named unflatten to reconstruct the JavaScript object from a parsed JSON structure.
The root cause of the vulnerability lies within the unflatten function. When it encountered a sparse array representation, the vulnerable code would instantiate an array with new Array(len), where len was a number read directly from the serialized input. Some JavaScript engines, like V8, will pre-allocate memory for the array up to a certain size. By providing a large value for len in a malicious payload, an attacker could force the server to allocate an extremely large amount of memory, causing the process to crash, resulting in a Denial of Service. The patch fixes this by avoiding new Array(len) and instead creating an empty array, manipulating it to force the engine to use a memory-efficient sparse representation, and only setting the length property at the end.