{"record":{"id":"06f3c60ea2b1d611","repo":"zloirock/core-js","slug":"wrong-length-06f3c6","errorCode":null,"errorMessage":"Wrong length","messagePattern":"Wrong length","errorType":"exception","errorClass":"RangeError","httpStatus":null,"severity":"error","filePath":"packages/core-js/modules/es.typed-array.set.js","lineNumber":42,"sourceCode":"// https://bugs.chromium.org/p/v8/issues/detail?id=11294 and other\nvar TO_OBJECT_BUG = WORKS_WITH_OBJECTS_AND_GENERIC_ON_TYPED_ARRAYS && ArrayBufferViewCore.NATIVE_ARRAY_BUFFER_VIEWS && fails(function () {\n  var array = new Int8Array(2);\n  array.set(1);\n  array.set('2', 1);\n  return array[0] !== 0 || array[1] !== 2;\n});\n\n// `%TypedArray%.prototype.set` method\n// https://tc39.es/ecma262/#sec-%typedarray%.prototype.set\nexportTypedArrayMethod('set', function set(arrayLike /* , offset */) {\n  aTypedArray(this);\n  var offset = toOffset(arguments.length > 1 ? arguments[1] : undefined, 1);\n  var src = toIndexedObject(arrayLike);\n  if (WORKS_WITH_OBJECTS_AND_GENERIC_ON_TYPED_ARRAYS) return call($set, this, src, offset);\n  var length = this.length;\n  var len = lengthOfArrayLike(src);\n  var index = 0;\n  if (len + offset > length) throw new RangeError('Wrong length');\n  while (index < len) this[offset + index] = src[index++];\n}, !WORKS_WITH_OBJECTS_AND_GENERIC_ON_TYPED_ARRAYS || TO_OBJECT_BUG);\n","sourceCodeStart":24,"sourceCodeEnd":45,"githubUrl":"https://github.com/zloirock/core-js/blob/84e45fba098dd3a177d5cf2247d06ab8e98d3790/packages/core-js/modules/es.typed-array.set.js#L24-L45","documentation":"TypeError-less RangeError thrown by the core-js polyfill of TypedArray.prototype.set(arrayLike, offset). The polyfill manually copies elements when the engine lacks generic typed-array set support, and before copying it checks whether source length plus the target offset exceeds the target typed array's length. If it does, the write would overflow the destination buffer, so a RangeError('Wrong length') is thrown.","triggerScenarios":"Calling typedArray.set(arrayLike, offset) via the core-js polyfill where arrayLike.length + offset > typedArray.length — e.g. new Int8Array(4).set([1,2,3,4,5]) or new Uint8Array(8).set(src, 6) with src.length 5 (6+5>8). Only thrown on engines where WORKS_WITH_OBJECTS_AND_GENERIC_ON_TYPED_ARRAYS is false (e.g. old IE); modern engines throw their own RangeError from native set.","commonSituations":"Copying a larger buffer chunk into a smaller view without slicing; an off-by-one or wrong offset constant; assuming set() truncates like subarray; running core-js polyfills on legacy browsers (IE11) where the native fast path is unavailable.","solutions":["Check src.length + offset <= typedArray.length before calling set, or slice the source","Increase the destination typed array size or use subarray to create a view of adequate length","Use offset 0 and a correctly sized source array","If the error appears only on legacy browsers, guard with a length check that works cross-engine"],"exampleFix":"// before\ntypedArray.set(newData, 10); // RangeError if newData.length + 10 > typedArray.length\n// after\nif (newData.length + 10 <= typedArray.length) {\n  typedArray.set(newData, 10);\n} else {\n  typedArray.set(newData.subarray(0, typedArray.length - 10), 10);\n}","handlingStrategy":"validation","validationCode":"function canSet(target, src, offset = 0) {\n  return Number.isInteger(offset) && offset >= 0 &&\n    src.length + offset <= target.length;\n}","typeGuard":"function isTypedArrayWithRoom(ta, srcLen, offset) {\n  return ArrayBuffer.isView(ta) &&\n    (ta.length ?? 0) + 0 >= srcLen + offset;\n}","tryCatchPattern":"try {\n  ta.set(src, offset);\n} catch (e) {\n  if (e instanceof RangeError && /Wrong length/.test(e.message)) {\n    ta.set(src.subarray(0, ta.length - offset), offset);\n  } else throw e;\n}","preventionTips":["Always check src.length + offset <= target.length before set","Remember set() never truncates silently in polyfilled engines","Slice or subarray the source when the destination is smaller","Test typed-array code on legacy browsers if you ship core-js polyfills"],"tags":["typed-array","range-error","polyfill","buffer"],"backgroundTag":"typed-array-set-wrong-length","analyzedSha":"84e45fba098dd3a177d5cf2247d06ab8e98d3790","analyzedAt":"2026-08-30T20:36:10.323Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}