Spec issues & errata · defect of the text · docs/spec-issues/53-string-length-overflow.md
53. String operations omit > 2^53 - 1 length checks required by §6.1.4's maximum String length
- Location
- §6.1.4 The String Type (
#sec-ecmascript-language-types-string-type), first paragraph; §22.1.3.18String.prototype.repeat(#sec-string.prototype.repeat), step 7; §22.1.3.5String.prototype.concat(#sec-string.prototype.concat), step 5.b; §13.15.3 ApplyStringOrNumericBinaryOperator (#sec-applystringornumericbinaryoperator), step 1.c.iii; §23.1.3.18.1 JoinIndexedProperties (#sec-joinindexedproperties), steps 4.a and 4.d.iii. - Kind
- contradiction (operations form String values exceeding §6.1.4's
2^53 - 1maximum length without throwing a RangeError). - Model erratum
StringLengthOverflow, baked-in SpecTec reading proposed ($StringTooLargeinspec/spectec/clauses/S13.spectec,S22.spectec,S23.spectec, andHost.ValueLaws.stringTooLargeinspec/spectec/prose/23-host-laws-values.spectec, withEngine.Hostanswering*true*past2^28and therefore past2^53 - 1; for the smaller finite-memory host limit2^28, see 54).- Upstream
- Checked 2026-11-20: none found for the missing
> 2^53 - 1check inrepeat,concat,+andJoinIndexedProperties(searched for String with "maximum length" and "RangeError"). Related: issue #4063 (closed, 2026-10), "Specify that exceeding resource limits may throw". - On this site
StringLengthOverflowon Spec issues & errata (defect of the text; SpecTec bakes in the proposed reading)
Text
§6.1.4:
The String type is the set of all ordered sequences of zero or more 16-bit unsigned integer values (“elements”) up to a maximum length of 253 - 1 elements.
String.prototype.repeat:
5. If n < 0 or n = +∞, throw a RangeError exception.
6. If n = 0, return the empty String.
7. Return the String value that is made from n copies of string appended together.
String.prototype.concat:
b. Set result to the string-concatenation of result and nextString.
ApplyStringOrNumericBinaryOperator:
iii. Return the string-concatenation of leftString and rightString.
JoinIndexedProperties:
a. If k > 0, set result to the string-concatenation of result and separator.
iii. Set result to the string-concatenation of result and elementString.
Problem
§6.1.4 bounds every String value to at most 253 - 1 code units (while StringPaddingBuiltinsImpl clamps
ToLength(_maxLength_) to ≤ 253 - 1, and Array.prototype.push / TypedArray operations explicitly throw past
253 - 1).
However, String.prototype.repeat, String.prototype.concat, string + (ApplyStringOrNumericBinaryOperator), and
JoinIndexedProperties have no length check before forming their result:
"ab".repeat(2 ** 52)passes step 5 (_n_ = 2^52is finite and non-negative), then step 7 asks for a String value of length2^53 > 2^53 - 1, which does not exist in §6.1.4's String type!- Likewise, concatenating or joining two Strings whose lengths sum past
2^53 - 1demands a String value outside the String type rather than throwing a RangeError.
Examples
try { "ab".repeat(2 ** 52); } catch (e) { print("repeat > 2^53-1: " + e.constructor.name); }
"ab".repeat(2 ** 52) |
|
|---|---|
| literal text | asks for a 2^53-element String value, contradicting §6.1.4 |
| V8, SpiderMonkey, JavaScriptCore | RangeError |
| formal model (proposed reading) | repeat > 2^53-1: RangeError |
Proposed wording
Before constructing the result String in String.prototype.repeat step 7 (_n_ × the length of _string_),
String.prototype.concat step 5.b, ApplyStringOrNumericBinaryOperator step 1.c.iii, and JoinIndexedProperties steps
4.a and 4.d.iii, throw a RangeError exception if the resulting length would exceed 253 - 1 (or the
implementation's smaller maximum String length; see 54).
test262
built-ins/String/prototype/repeat/ tests negative and +Infinity counts (repeat(-1), repeat(Infinity)), not finite
counts whose product with _string_'s length exceeds 2^53 - 1.