The vulnerability lies in how the devalue library handles the serialization of sparse arrays in its stringify and uneval functions. The original implementation in both functions iterated through all array indices up to the array's length. This becomes a problem with sparse arrays, which can have a very large length but only a few actual elements. For instance, an array like const arr = []; arr[1000000] = 'value'; has a length of 1,000,001 but only one element. The vulnerable code would loop 1,000,001 times, consuming significant CPU and memory, leading to a Denial of Service (DoS). The patch addresses this by introducing a check to detect if an array is sparse. If it is, a more efficient serialization method is used that only considers the populated indices, thus avoiding the costly iteration over empty slots. The stringify function now uses a special SPARSE encoding, and the uneval function generates an Object.assign(Array(...), ...) expression to reconstruct the sparse array efficiently.