{"record":{"id":"75eb0668ef505f5f","repo":"zloirock/core-js","slug":"wrong-length-75eb06","errorCode":null,"errorMessage":"Wrong length","messagePattern":"Wrong length","errorType":"exception","errorClass":"RangeError","httpStatus":null,"severity":"error","filePath":"packages/core-js/internals/typed-array-constructor.js","lineNumber":160,"sourceCode":"      });\n    };\n\n    if (!NATIVE_ARRAY_BUFFER_VIEWS) {\n      TypedArrayConstructor = wrapper(function (that, data, offset, $length) {\n        anInstance(that, TypedArrayConstructorPrototype);\n        var index = 0;\n        var byteOffset = 0;\n        var buffer, byteLength, length;\n        if (!isObject(data)) {\n          length = toIndex(data);\n          byteLength = length * BYTES;\n          buffer = new ArrayBuffer(byteLength);\n        } else if (isArrayBuffer(data)) {\n          buffer = data;\n          byteOffset = toOffset(offset, BYTES);\n          var $len = data.byteLength;\n          if ($length === undefined) {\n            if ($len % BYTES) throw new RangeError(WRONG_LENGTH);\n            byteLength = $len - byteOffset;\n            if (byteLength < 0) throw new RangeError(WRONG_LENGTH);\n          } else {\n            byteLength = toIndex($length) * BYTES;\n            if (byteLength + byteOffset > $len) throw new RangeError(WRONG_LENGTH);\n          }\n          length = byteLength / BYTES;\n        } else if (isTypedArray(data)) {\n          return arrayFromConstructorAndList(TypedArrayConstructor, data);\n        } else {\n          return call(typedArrayFrom, TypedArrayConstructor, data);\n        }\n        setInternalState(that, {\n          buffer: buffer,\n          byteOffset: byteOffset,\n          byteLength: byteLength,\n          length: length,\n          view: new DataView(buffer)","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/zloirock/core-js/blob/84e45fba098dd3a177d5cf2247d06ab8e98d3790/packages/core-js/internals/typed-array-constructor.js#L142-L178","documentation":"When constructing a typed array from an existing ArrayBuffer with no explicit length, core-js validates the buffer against the element size (BYTES). If the buffer's byte length is not a multiple of the element size, or the byteOffset/derived length would be negative or out of bounds, it throws this RangeError. This mirrors the spec's ArrayBuffer-allocated-bytes validation for `new Float32Array(buffer)` style calls.","triggerScenarios":"`new Float64Array(someArrayBuffer)` where the buffer's byteLength is not divisible by 8; similarly new Uint32Array(buf) with a buffer length not divisible by 4, or where the given byteOffset exceeds the buffer length.","commonSituations":"Parsing binary file formats where headers leave a trailing byte, buffers built by manual concatenation with padding, or slicing an ArrayBuffer at a non-aligned offset before wrapping it in a typed array.","solutions":["Check `buffer.byteLength % elementSize === 0` before constructing; slice/trim the buffer if not.","Pass an explicit length: `new Float32Array(buffer, byteOffset, length)` with a valid length.","Align the buffer: allocate from the start with byteLength = n * elementSize.","Verify the byteOffset argument is a multiple of the element size and within bounds."],"exampleFix":"// before\nconst buf = new ArrayBuffer(10);\nconst f64 = new Float64Array(buf); // RangeError: Wrong length\n// after\nconst buf = new ArrayBuffer(16); // 2 * 8 bytes\nconst f64 = new Float64Array(buf);","handlingStrategy":"validation","validationCode":"function canWrap(buffer, ElementCtor, byteOffset = 0) {\n  const bpe = ElementCtor.BYTES_PER_ELEMENT;\n  return buffer.byteLength % bpe === 0 && byteOffset % bpe === 0;\n}\nif (!canWrap(buf, Float64Array)) buf = buf.slice(0, buf.byteLength - (buf.byteLength % 8));","typeGuard":"function isAligned(buffer, bytesPerElement) { return buffer instanceof ArrayBuffer && buffer.byteLength % bytesPerElement === 0; }","tryCatchPattern":"try {\n  view = new Float64Array(buf);\n} catch (e) {\n  if (e instanceof RangeError && e.message === 'Wrong length') {\n    view = new Float64Array(buf.slice(0, buf.byteLength - (buf.byteLength % 8)));\n  } else throw e;\n}","preventionTips":["Ensure buffer.byteLength is a multiple of the element size before wrapping.","Keep byteOffset aligned to the element size.","When parsing binary formats, trim trailing padding bytes before constructing views."],"tags":["core-js","typed-array","arraybuffer","rangeerror"],"backgroundTag":"typed-array-wrong-length","analyzedSha":"84e45fba098dd3a177d5cf2247d06ab8e98d3790","analyzedAt":"2026-08-30T20:36:10.323Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}