{"record":{"id":"c4f517c8d0022335","repo":"santifer/career-ops","slug":"the-published-index-exceeds-max-index-bytes-byt","errorCode":null,"errorMessage":"the published index exceeds ${MAX_INDEX_BYTES} bytes (${declared}): ${url}","messagePattern":"the published index exceeds (.+?) bytes \\((.+?)\\): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"plugins/h1b-sponsor/install-h1b-index.mjs","lineNumber":149,"sourceCode":"    ? null\n    : String(doc.version).slice(0, 64);\n  return { filename, sha256, version };\n}\n\n/**\n * Stream the asset to `tmpFile`, hashing as it goes, and return the digest.\n *\n * Streamed rather than buffered: the body is millions of times the size of\n * anything else this plugin reads, and readBoundedText's 1 MiB ceiling exists\n * precisely because nothing on the API path should ever be this big. Hashing\n * during the write means the file is never read a second time to verify it.\n */\nasync function downloadAsset(fetchImpl, url, tmpFile) {\n  return fetchImpl(url, { timeoutMs: ASSET_TIMEOUT_MS }, async res => {\n    if (res.status !== 200) throw new Error(`could not download the index (HTTP ${res.status}): ${url}`);\n    const declared = Number(res.headers?.get?.('content-length'));\n    if (Number.isFinite(declared) && declared > MAX_INDEX_BYTES) {\n      throw new Error(`the published index exceeds ${MAX_INDEX_BYTES} bytes (${declared}): ${url}`);\n    }\n    if (!res.body || typeof res.body.getReader !== 'function') {\n      throw new Error(`the index response carried no readable body: ${url}`);\n    }\n\n    const hash = createHash('sha256');\n    const out = createWriteStream(tmpFile);\n    // A write failure (disk full, an unwritable target) arrives as an 'error'\n    // event on the stream, and an EventEmitter error with no listener is an\n    // uncaughtException: the CLI died on a stack trace instead of returning\n    // the envelope, and the cleanup that removes the partial .tmp file never\n    // ran. Recording the error here makes the crash impossible; the checks\n    // below turn it into the ordinary failure it is. once(out, 'drain') needs\n    // no extra wiring, it already rejects when 'error' fires mid-wait.\n    let writeError = null;\n    out.on('error', err => { writeError = err; });\n    const reader = res.body.getReader();\n    let total = 0;","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/santifer/career-ops/blob/aac998c7ed7248ea853b720ceeb1fdbeb322fc5d/plugins/h1b-sponsor/install-h1b-index.mjs#L131-L167","documentation":"downloadAsset throws this when the response's declared content-length header exceeds MAX_INDEX_BYTES. The plugin caps the published index size because nothing on the API path should be that large; a bigger declared body suggests the wrong asset, a hijacked/misconfigured endpoint, or an attack.","triggerScenarios":"downloadAsset reads res.headers.get('content-length'); Number(declared) is finite and > MAX_INDEX_BYTES. Happens immediately, before any body bytes are read.","commonSituations":"Pointing H1B_API_BASE or the asset URL at the wrong host/file; the upstream project republishes a much larger index format; a malicious mirror serving an oversized payload.","solutions":["Verify the asset URL points at the official published index, not an unrelated file.","Check the actual size of the upstream index; if the format legitimately grew, update MAX_INDEX_BYTES in the plugin.","Re-run against the default endpoint (unset custom base/asset overrides)."],"exampleFix":"null","handlingStrategy":"validation","validationCode":"const head = await fetch(url, { method: 'HEAD' });\nconst len = Number(head.headers.get('content-length'));\nif (Number.isFinite(len) && len > MAX_INDEX_BYTES) throw new Error(`upstream index too large: ${len} bytes`);","typeGuard":null,"tryCatchPattern":"try {\n  await installIndex();\n} catch (e) {\n  if (e.message.includes('exceeds') && e.message.includes('bytes')) {\n    console.error('Download exceeds the plugin size cap; verify you are pointed at the official index.');\n  }\n}","preventionTips":["Always point ASSET/base overrides at the official published index.","Check the upstream index size after major format releases and update the cap knowingly.","Treat oversized responses as a supply-chain red flag, not something to work around by raising the limit casually."],"tags":["download","size-limit","validation"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"aac998c7ed7248ea853b720ceeb1fdbeb322fc5d","analyzedAt":"2026-09-16T06:35:29.214Z","contentChangedAt":"2026-09-16T06:35:29.214Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}