{"record":{"id":"3945e3c95d82c9cb","repo":"zloirock/core-js","slug":"wrong-index","errorCode":null,"errorMessage":"Wrong index","messagePattern":"Wrong index","errorType":"exception","errorClass":"RangeError","httpStatus":null,"severity":"error","filePath":"packages/core-js/internals/array-buffer.js","lineNumber":86,"sourceCode":"\nvar packFloat64 = function (number) {\n  return packIEEE754(number, 52, 8);\n};\n\nvar addGetter = function (Constructor, key, getInternalState) {\n  defineBuiltInAccessor(Constructor[PROTOTYPE], key, {\n    configurable: true,\n    get: function () {\n      return getInternalState(this)[key];\n    }\n  });\n};\n\nvar get = function (view, count, index, isLittleEndian) {\n  var store = getInternalDataViewState(view);\n  var intIndex = toIndex(index);\n  var boolIsLittleEndian = !!isLittleEndian;\n  if (intIndex + count > store.byteLength) throw new RangeError(WRONG_INDEX);\n  var bytes = store.bytes;\n  var start = intIndex + store.byteOffset;\n  var pack = arraySlice(bytes, start, start + count);\n  return boolIsLittleEndian ? pack : reverse(pack);\n};\n\nvar set = function (view, count, index, conversion, value, isLittleEndian) {\n  var store = getInternalDataViewState(view);\n  var intIndex = toIndex(index);\n  var pack = conversion(+value);\n  var boolIsLittleEndian = !!isLittleEndian;\n  if (intIndex + count > store.byteLength) throw new RangeError(WRONG_INDEX);\n  var bytes = store.bytes;\n  var start = intIndex + store.byteOffset;\n  for (var i = 0; i < count; i++) bytes[start + i] = pack[boolIsLittleEndian ? i : count - i - 1];\n};\n\nif (!NATIVE_ARRAY_BUFFER) {","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/zloirock/core-js/blob/84e45fba098dd3a177d5cf2247d06ab8e98d3790/packages/core-js/internals/array-buffer.js#L68-L104","documentation":"The DataView.prototype.get* fallback in core-js reads `count` bytes at byte `index`. toIndex coerces and validates the index; if index + count exceeds the view's byteLength, a RangeError 'Wrong index' is thrown, matching the spec's out-of-bounds read requirement.","triggerScenarios":"Calling dataView.getFloat64(off) / getUint32(off) etc. where off + elementSize > view.byteLength, or a negative/non-integer offset that toIndex rejects. Reached via the `bytes` accessor used by every DataView getX method.","commonSituations":"Hand-rolled binary parsers using fixed offsets against shorter buffers; off-by-one in loop bounds; forgetting that a DataView with byteLength limited at construction only exposes that slice; parsing truncated network/file payloads.","solutions":["Clamp offsets: if (off + size <= view.byteLength) read.","Check dataview.byteLength before each read and size the read to remaining bytes.","Verify the buffer wasn't created with a truncated byteLength argument.","Catch RangeError around reads when parsing untrusted-length data."],"exampleFix":"// before\nvar v = dv.getFloat64(dv.byteLength - 4); // RangeError: Wrong index\n// after\nvar v = dv.getFloat64(dv.byteLength - 8);","handlingStrategy":"validation","validationCode":"function canRead(dv, offset, size){ return Number.isInteger(offset) && offset >= 0 && offset + size <= dv.byteLength; }\nif (!canRead(dv, off, 8)) throw new RangeError('read out of bounds');","typeGuard":null,"tryCatchPattern":"try { value = dv.getFloat64(off); } catch (e) { if (e instanceof RangeError && /Wrong index/.test(e.message)) return readTruncated(); throw e; }","preventionTips":["Check dv.byteLength before each typed read (offset + elementSize).","Remember a DataView's byteLength may be smaller than its buffer's.","Use a cursor/reader abstraction that clamps offsets automatically.","Validate payload length before parsing fixed-size structs."],"tags":["rangeerror","dataview","out-of-bounds","binary-parsing"],"backgroundTag":"dataview-out-of-bounds","analyzedSha":"84e45fba098dd3a177d5cf2247d06ab8e98d3790","analyzedAt":"2026-08-30T20:36:10.323Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}