{"record":{"id":"b759de80093feace","repo":"zloirock/core-js","slug":"wrong-offset","errorCode":null,"errorMessage":"Wrong offset","messagePattern":"Wrong offset","errorType":"exception","errorClass":"RangeError","httpStatus":null,"severity":"error","filePath":"packages/core-js/internals/array-buffer.js","lineNumber":127,"sourceCode":"      type: ARRAY_BUFFER,\n      bytes: fill(Array(byteLength), 0),\n      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","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/zloirock/core-js/blob/84e45fba098dd3a177d5cf2247d06ab8e98d3790/packages/core-js/internals/array-buffer.js#L109-L145","documentation":"The non-native DataView polyfill constructor validates byteOffset: after converting with toIntegerOrInfinity, an offset below 0 or above buffer.byteLength throws RangeError 'Wrong offset'. This mirrors the spec's DataView(buffer, byteOffset [, length]) offset validation.","triggerScenarios":"new DataView(buffer, negativeNumber), new DataView(buf, buf.byteLength + 1), or a non-numeric offset coerced to NaN/negative. Also triggered transitively by code constructing views with computed offsets from headers.","commonSituations":"Offset parsed from a binary header that is garbage/truncated data; sign errors in manual pointer arithmetic; reusing an offset computed against a larger buffer on a smaller one.","solutions":["Clamp the offset: Math.min(Math.max(0, off), buffer.byteLength).","Validate the offset against buffer.byteLength before constructing.","Sanitize offsets parsed from file/network data before use.","Catch RangeError around DataView construction when offsets are data-derived."],"exampleFix":"// before\nvar dv = new DataView(buf, buf.byteLength + 8); // RangeError: Wrong offset\n// after\nvar off = Math.min(buf.byteLength, headerOffset);\nvar dv = new DataView(buf, off);","handlingStrategy":"validation","validationCode":"function safeDataView(buf, off, len){ off = Math.min(Math.max(0, off | 0), buf.byteLength); return new DataView(buf, off, len === undefined ? undefined : Math.min(len, buf.byteLength - off)); }","typeGuard":null,"tryCatchPattern":"try { dv = new DataView(buf, off); } catch (e) { if (e instanceof RangeError && /Wrong offset/.test(e.message)) { off = 0; dv = new DataView(buf, off); } else throw e; }","preventionTips":["Clamp byteOffset into [0, buffer.byteLength] before construction.","Sanitize offsets parsed from binary headers before trusting them.","Check sign of computed offsets (pointer arithmetic errors).","Remember offsets are relative to the buffer, not to a previously created view."],"tags":["rangeerror","dataview","offset","out-of-bounds"],"backgroundTag":"dataview-wrong-offset","analyzedSha":"84e45fba098dd3a177d5cf2247d06ab8e98d3790","analyzedAt":"2026-08-30T20:36:10.323Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}