{"record":{"id":"ce02fca7d56708fb","repo":"denoland/deno","slug":"the-region-specified-by-view-is-larger-than-byobre","errorCode":null,"errorMessage":"The region specified by view is larger than byobRequest","messagePattern":"The region specified by view is larger than byobRequest","errorType":"exception","errorClass":"RangeError","httpStatus":null,"severity":"error","filePath":"ext/web/06_streams.js","lineNumber":2828,"sourceCode":"      throw new TypeError(\n        \"The view's length must be greater than 0 when calling respondWithNewView() on a readable stream\",\n      );\n    }\n  }\n  // deno-lint-ignore deno-internal/prefer-primordials\n  if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !== byteOffset) {\n    throw new RangeError(\n      \"The region specified by view does not match byobRequest\",\n    );\n  }\n  if (firstDescriptor.bufferByteLength !== getArrayBufferByteLength(buffer)) {\n    throw new RangeError(\n      \"The buffer of view has different capacity than byobRequest\",\n    );\n  }\n  // deno-lint-ignore deno-internal/prefer-primordials\n  if (firstDescriptor.bytesFilled + byteLength > firstDescriptor.byteLength) {\n    throw new RangeError(\n      \"The region specified by view is larger than byobRequest\",\n    );\n  }\n  firstDescriptor.buffer = ArrayBufferPrototypeTransferToFixedLength(buffer);\n  readableByteStreamControllerRespondInternal(controller, byteLength);\n}\n\n/**\n * @param {ReadableByteStreamController} controller\n * @returns {PullIntoDescriptor}\n */\nfunction readableByteStreamControllerShiftPendingPullInto(controller) {\n  assert(controller[_byobRequest] === null);\n  return controller[_pendingPullIntos].dequeue();\n}\n\n/**\n * @param {ReadableByteStreamController} controller","sourceCodeStart":2810,"sourceCodeEnd":2846,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/web/06_streams.js#L2810-L2846","documentation":"RangeError from respondWithNewView(view): firstDescriptor.bytesFilled + view.byteLength exceeds firstDescriptor.byteLength. The replacement view covers more bytes than remain unfilled in the pending pull-into, i.e. the region handed back is larger than the request can accept.","triggerScenarios":"Responding with the full original view after partial fills already consumed its head; enlarging the view (subarray with a larger end) before responding; combining several chunks into one oversized region.","commonSituations":"Partial-write loops that grow the response region; forgetting that bytesFilled advances with earlier responses on the same request; example code that responds with the whole buffer.","solutions":["Size the view to the bytes written this step: view.subarray(start, start + n).","Track the fill point alongside the request and respond only with the remaining span.","Prefer respond(n), which validates the total against the descriptor for you."],"exampleFix":"// before\nbyob.respondWithNewView(byob.view); // whole view, part already filled -> RangeError\n\n// after\nconst v = byob.view.subarray(0, n); // only the region written now\nbyob.respondWithNewView(v);","handlingStrategy":"validation","validationCode":"// region must fit the remaining unfilled space of the request\nif (view.byteLength > byob.view.byteLength) {\n  view = view.subarray(0, byob.view.byteLength);\n}\nbyob.respondWithNewView(view);","typeGuard":null,"tryCatchPattern":"try {\n  byob.respondWithNewView(view);\n} catch (e) {\n  if (e instanceof RangeError && e.message.includes('larger than byobRequest')) {\n    byob.respond(byob.view.byteLength);\n    return;\n  }\n  throw e;\n}","preventionTips":["The returned region plus what is already filled must fit the original request.","One respond per request, sized to exactly the bytes written, avoids region math."],"tags":["readable-stream","byob-reader","respondwithnewview","rangeerror","buffer-overflow"],"backgroundTag":"byob-request-respond-misuse","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}