diff --git a/src/builtins/array-join.tq b/src/builtins/array-join.tq index 84b967fa597..9d107f2b4e0 100644 --- a/src/builtins/array-join.tq +++ b/src/builtins/array-join.tq @@ -203,6 +203,11 @@ struct Buffer { implicit context: Context)(nofSeparators: intptr, separatorLength: intptr, write: bool): void { if (nofSeparators == 0 || separatorLength == 0) return; + // nofSeparators is the unguarded sum of up to kMaxArrayLength increments. + // On 32-bit targets intptr is int32 and the count can wrap negative; treat + // that as length overflow instead of letting the negative value reach the + // chunk-list (where WriteChunkListToFlat reads it as repeat_last). + if (nofSeparators < 0) ThrowInvalidStringLength(context); const nofSeparatorsInt: intptr = nofSeparators; const sepsLen: intptr = separatorLength * nofSeparatorsInt;