{"record":{"id":"5a98d67be8e5056a","repo":"tursodatabase/turso","slug":"payload-start-out-of-bounds-on-page-root-page","errorCode":null,"errorMessage":"payload start out of bounds on page {root_page}","messagePattern":"payload start out of bounds on page (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"testing/sqltest/src/generator/mod.rs","lineNumber":1070,"sourceCode":"    let first_cell_ptr =\n        u16::from_be_bytes([bytes[ptr_array_start], bytes[ptr_array_start + 1]]) as usize;\n    let cell_start = page_start + first_cell_ptr;\n    anyhow::ensure!(\n        cell_start < bytes.len(),\n        \"cell pointer out of bounds on page {root_page}\"\n    );\n\n    let (_, payload_varint_len) = parse_sqlite_varint(&bytes, cell_start)?;\n    let (_, rowid_varint_len) = parse_sqlite_varint(&bytes, cell_start + payload_varint_len)?;\n    let payload_start = cell_start + payload_varint_len + rowid_varint_len;\n    anyhow::ensure!(\n        payload_start < bytes.len(),\n        \"payload start out of bounds on page {root_page}\"\n    );\n\n    let (header_size, header_size_varint_len) = parse_sqlite_varint(&bytes, payload_start)?;\n    let header_end = payload_start + header_size as usize;\n    anyhow::ensure!(\n        header_end <= bytes.len(),\n        \"record header out of bounds on page {root_page}\"\n    );\n\n    let mut serial_offset = payload_start + header_size_varint_len;\n    for _ in 0..patch.column_index {\n        let (_, serial_len) = parse_sqlite_varint(&bytes, serial_offset)?;\n        serial_offset += serial_len;\n    }\n    anyhow::ensure!(\n        serial_offset < header_end,\n        \"record has no column {} on page {root_page}\",\n        patch.column_index\n    );\n    anyhow::ensure!(\n        bytes[serial_offset] == patch.expected_serial_type,\n        \"unexpected serial type {} for column {} of the fixture row, expected {}\",\n        bytes[serial_offset],","sourceCodeStart":1052,"sourceCodeEnd":1088,"githubUrl":"https://github.com/tursodatabase/turso/blob/8d4a589f8d13ac184700d2a8f724f27e1995be3b/testing/sqltest/src/generator/mod.rs#L1052-L1088","documentation":"The generator reads the raw bytes of a database page to locate the first record's payload, and validates that the computed payload offset lies within the page bytes. If the offset is beyond the page size, the fixture's expected page layout does not match the actual file, so it refuses to patch and reports the offending root page.","triggerScenarios":"`patch_first_row_serial_type` computes `payload_start` from the page's cell pointer and cell header, and it exceeds `bytes.len()` — usually because the wrong `root_page` or `page_size` was passed, or the page is not a table leaf page.","commonSituations":"Fixture schema changed (row moved to a different root page), wrong page_size argument, or pointing the patcher at an interior/overflow page instead of a leaf containing the first row.","solutions":["Verify the `root_page` matches the table's actual root page in the current schema.","Ensure the `page_size` argument matches the database's PRAGMA page_size.","Confirm the page is a table b-tree leaf (0x0D) containing the first row before patching."],"exampleFix":"// before\nlet root_page = 2; // stale after schema change\n// after\nlet root_page = db_first_table_root_page(&db_path, \"t\")?; // look up dynamically","handlingStrategy":"validation","validationCode":"let page = read_page(&db_path, root_page, page_size)?;\nassert_eq!(page[0], 0x0D, \"page {root_page} must be a table leaf\");\nassert!(payload_start < page.len(), \"payload_start {payload_start} out of bounds\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Look up root pages from the schema rather than hardcoding","Pass page_size from PRAGMA page_size, not a constant","Re-derive root_page after any schema change"],"tags":["sqlite","fixture","page-layout","testing"],"backgroundTag":"index-out-of-bounds","analyzedSha":"8d4a589f8d13ac184700d2a8f724f27e1995be3b","analyzedAt":"2026-09-20T13:18:14.658Z","contentChangedAt":"2026-09-20T13:18:14.658Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}