{"record":{"id":"fd978314ce968ab2","repo":"copy/v86","slug":"invalid-info-block-length","errorCode":null,"errorMessage":"Invalid info block length: ","messagePattern":"Invalid info block length: ","errorType":"exception","errorClass":"StateLoadError","httpStatus":null,"severity":"error","filePath":"src/state.js","lineNumber":314,"sourceCode":"                buffers.push(cpu.wasm_memory.buffer.slice(offset, offset + buffer_info.length));\n                cpu.zstd_read_free(ptr, front_padding + buffer_info.length);\n            }\n\n            position += front_padding + buffer_info.length;\n        }\n\n        state_object = restore_buffers(state_object, buffers);\n        cpu.set_state(state_object);\n\n        cpu.zstd_free_ctx(ctx);\n    }\n    else\n    {\n        const info_block_len = read_state_header(state, true);\n\n        if(info_block_len < 0 || info_block_len + 12 >= state.length)\n        {\n            throw new StateLoadError(\"Invalid info block length: \" + info_block_len);\n        }\n\n        const info_block_buffer = state.subarray(STATE_INFO_BLOCK_START, STATE_INFO_BLOCK_START + info_block_len);\n        const info_block_obj = read_info_block(info_block_buffer);\n        let state_object = info_block_obj[\"state\"];\n        const buffer_infos = info_block_obj[\"buffer_infos\"];\n        let buffer_block_start = STATE_INFO_BLOCK_START + info_block_len;\n        buffer_block_start = buffer_block_start + 3 & ~3;\n\n        const buffers = buffer_infos.map(buffer_info => {\n            const offset = buffer_block_start + buffer_info.offset;\n            return state.buffer.slice(offset, offset + buffer_info.length);\n        });\n\n        state_object = restore_buffers(state_object, buffers);\n        cpu.set_state(state_object);\n    }\n}","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/copy/v86/blob/180830d539dcc87db1a191febf6c914f516d102f/src/state.js#L296-L332","documentation":"restore_state reads the info-block length from the header and sanity-checks it: it must be non-negative and the info block must fit inside the state buffer (info_block_len + 12 < state.length). Out-of-range values mean the header or dump is corrupted, so StateLoadError('Invalid info block length: N') is thrown before the info block is parsed.","triggerScenarios":"restore_state called with a state whose header STATE_INDEX_INFO_LEN is negative (int32 overflow/corruption) or so large the info block would run past the end of the buffer — corrupted header bytes, bit-flips in storage, or a hand-crafted/mis-sliced buffer.","commonSituations":"Bit rot or corruption in stored state files (disk, cloud sync); states manipulated by external tools; memory corruption between capture and restore in the same page (rare).","solutions":["Discard and re-capture the state file — a corrupt header usually can't be repaired safely","Re-download the state and verify a checksum against the source","Check that the buffer wasn't modified/sliced between capture and restore in your app","Ensure the state was saved by a compatible emulator version (see version checks)"],"exampleFix":"// before\nemulator.restore_state(corruptState); // throws deep inside\n// after\ntry {\n    emulator.restore_state(state);\n} catch (e) {\n    if (String(e).includes(\"Invalid info block length\")) {\n    recoverFromBackupState();\n    }\n}","handlingStrategy":"validation","validationCode":"function infoBlockFits(buf) {\n    if (!(buf instanceof Uint8Array) || buf.byteLength < 12) return false;\n    const infoLen = new Int32Array(buf.buffer, buf.byteOffset, 4)[2]; // STATE_INDEX_INFO_LEN\n    return infoLen >= 0 && infoLen + 12 < buf.byteLength;\n}\nif (!infoBlockFits(state)) throw new Error(\"corrupt state header\");","typeGuard":null,"tryCatchPattern":"try {\n    emulator.restore_state(state);\n} catch (e) {\n    if (e instanceof StateLoadError && /Invalid info block length/.test(e.message)) {\n    restoreFromBackup(); // header is corrupt, not repairable\n    } else throw e;\n}","preventionTips":["Store checksums with saved states and verify before restore","Re-capture states showing header corruption — don't attempt repair","Protect state blobs from post-capture mutation in your app","Test storage/transfer paths for bit-level integrity"],"tags":["state","corruption","validation"],"backgroundTag":"state-load-failed","analyzedSha":"180830d539dcc87db1a191febf6c914f516d102f","analyzedAt":"2026-08-31T22:39:37.599Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}