{"record":{"id":"6f93c67ceb4bc65d","repo":"zloirock/core-js","slug":"wrong-length","errorCode":null,"errorMessage":"Wrong length","messagePattern":"Wrong length","errorType":"exception","errorClass":"RangeError","httpStatus":null,"severity":"error","filePath":"packages/core-js/internals/array-buffer.js","lineNumber":129,"sourceCode":"      byteLength: byteLength\n    });\n    if (!DESCRIPTORS) {\n      this.byteLength = byteLength;\n      this.detached = false;\n    }\n  };\n\n  ArrayBufferPrototype = $ArrayBuffer[PROTOTYPE];\n\n  $DataView = function DataView(buffer, byteOffset, byteLength) {\n    anInstance(this, DataViewPrototype);\n    anInstance(buffer, ArrayBufferPrototype);\n    var bufferState = getInternalArrayBufferState(buffer);\n    var bufferLength = bufferState.byteLength;\n    var offset = toIntegerOrInfinity(byteOffset);\n    if (offset < 0 || offset > bufferLength) throw new RangeError('Wrong offset');\n    byteLength = byteLength === undefined ? bufferLength - offset : toIndex(byteLength);\n    if (offset + byteLength > bufferLength) throw new RangeError(WRONG_LENGTH);\n    setInternalState(this, {\n      type: DATA_VIEW,\n      buffer: buffer,\n      byteLength: byteLength,\n      byteOffset: offset,\n      bytes: bufferState.bytes\n    });\n    if (!DESCRIPTORS) {\n      this.buffer = buffer;\n      this.byteLength = byteLength;\n      this.byteOffset = offset;\n    }\n  };\n\n  DataViewPrototype = $DataView[PROTOTYPE];\n\n  if (DESCRIPTORS) {\n    addGetter($ArrayBuffer, 'byteLength', getInternalArrayBufferState);","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/zloirock/core-js/blob/84e45fba098dd3a177d5cf2247d06ab8e98d3790/packages/core-js/internals/array-buffer.js#L111-L147","documentation":"After validating the offset, the polyfilled DataView constructor validates the (possibly defaulted) byteLength: if byteOffset + byteLength exceeds buffer.byteLength, it throws RangeError WRONG_LENGTH ('Wrong length'). This enforces that the view stays within the buffer, per spec.","triggerScenarios":"new DataView(buf, off, len) where off + len > buf.byteLength, or explicit byteLength exceeding remaining space after the offset.","commonSituations":"Sizing views from length fields read out of corrupt/truncated payloads; arithmetic mistakes combining offset+length; code assuming length is absolute buffer size rather than view size.","solutions":["Compute length from remaining bytes: Math.min(len, buf.byteLength - off).","Validate off + len <= buf.byteLength before constructing.","Sanitize lengths parsed from external data.","Catch RangeError to translate into an application-level 'malformed payload' error."],"exampleFix":"// before\nvar dv = new DataView(buf, 0, buf.byteLength + 16); // RangeError: Wrong length\n// after\nvar dv = new DataView(buf, 0, buf.byteLength);","handlingStrategy":"validation","validationCode":"function safeDataView(buf, off, len){ if (off + len > buf.byteLength) len = buf.byteLength - off; return new DataView(buf, off, len); }","typeGuard":null,"tryCatchPattern":"try { dv = new DataView(buf, off, len); } catch (e) { if (e instanceof RangeError && /Wrong length/.test(e.message)) { len = buf.byteLength - off; dv = new DataView(buf, off, Math.max(0, len)); } else throw e; }","preventionTips":["Enforce off + len <= buffer.byteLength before construction.","Treat lengths read from payloads as untrusted; clamp them.","Remember the length argument is the view size, not an absolute buffer size.","Use Math.min(len, buf.byteLength - off) for derived views."],"tags":["rangeerror","dataview","length","out-of-bounds"],"backgroundTag":"dataview-wrong-length","analyzedSha":"84e45fba098dd3a177d5cf2247d06ab8e98d3790","analyzedAt":"2026-08-30T20:36:10.323Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}