{"record":{"id":"55a365b05ede7f06","repo":"tursodatabase/turso","slug":"invalid-cell-payload","errorCode":null,"errorMessage":"invalid cell payload","messagePattern":"invalid cell payload","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"core/storage/btree.rs","lineNumber":6825,"sourceCode":"        let contents = page.get_contents();\n        let cell_idx = self.stack.current_cell_index();\n        let (payload, payload_size, first_overflow_page) =\n            contents.cell_read_payload_ptr(cell_idx as usize, self.payload_limits)?;\n        if let Some(next_page) = first_overflow_page {\n            return_if_io!(self.process_overflow_read(payload, next_page, payload_size))\n        } else {\n            let record = self\n                .get_immutable_record_or_create()?\n                .expect(\"record was allocated above\");\n            record.invalidate();\n            crate::with_btree_allocation_site!(RecordPayload, record.start_serialization(payload))?;\n        };\n\n        Ok(IOResult::Done(self.reusable_immutable_record.as_ref()))\n    }\n\n    #[inline(always)]\n    fn record_payload(&mut self) -> IOResultOr<Option<&[u8]>> {\n        if self.needs_restore() {\n            return restore_record_payload(self);\n        }\n        if self.null_flag || !self.has_record() {\n            return Ok(IOResult::Done(None));\n        }\n        let noted = self.noted_payload;\n        if noted.size != 0 {\n            let size = noted.size as usize;\n            // A cell that keeps its whole payload on the page: the rowid\n            // read already found where it starts.\n            if size <= self.payload_limits.max_local_table {\n                let start = noted.start as usize;\n                let contents = self.stack.top_ref().get_contents();\n                if let Some(payload) = contents.payload_on_page(start, size) {\n                    return Ok(IOResult::Done(Some(payload)));\n                }\n            }","sourceCodeStart":6807,"sourceCodeEnd":6843,"githubUrl":"https://github.com/tursodatabase/turso/blob/8d4a589f8d13ac184700d2a8f724f27e1995be3b/core/storage/btree.rs#L6807-L6843","documentation":"After building the replacement interior cell payload (4-byte big-endian left-child pointer followed by the key), the parent update parses cell_payload[..4] back into a page number with try_into().expect(\"invalid cell payload\"). The panic fires when the freshly built payload is shorter than 4 bytes, which the builders (child_pointer.to_be_bytes() extension) should never produce.","triggerScenarios":"Interior-node replacement on DELETE where the payload Vec came out empty or truncated - a logic bug in the payload construction arms (TableLeafCell / IndexLeafCell rewriting) or an allocation failure swallowed earlier in the chain.","commonSituations":"Engine regressions in cell serialization, corrupted cell metadata producing zero-length writes, allocation-failure paths in with_btree_allocation_site! macros.","solutions":["Report to Turso with the exact DELETE statement and a copy of the database - payload construction cannot legitimately produce <4 bytes","Run PRAGMA integrity_check to rule out corruption","Retry the operation on a fresh connection; pre-commit disk state is unaffected","Upgrade the engine - the cell-building code paths are under active development"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"let result = std::panic::catch_unwind(AssertUnwindSafe(|| {\n    conn.execute(\"DELETE FROM idx_t ON ...\", ())  // any delete touching interior cells\n}));\nif result.is_err() { conn.close().ok(); /* reopen, verify, report */ }","preventionTips":["Run PRAGMA integrity_check after abnormal terminations before further writes","Test upgrades against delete-heavy datasets to catch serialization regressions early","Use transactions around deletes so partial effects are never committed after a panic","Report minimal reproductions upstream"],"tags":["btree","cell-payload","delete","panic"],"backgroundTag":"corrupt-btree-cell","analyzedSha":"8d4a589f8d13ac184700d2a8f724f27e1995be3b","analyzedAt":"2026-08-20T07:02:18.389Z","contentChangedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}