{"record":{"id":"f9c55773f4527421","repo":"quickwit-oss/tantivy","slug":"invaliddata-f9c557","errorCode":"InvalidData","errorMessage":"invalid bool value on deserialization, data corrupted","messagePattern":"invalid bool value on deserialization, data corrupted","errorType":"error_code","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"common/src/serialize.rs","lineNumber":224,"sourceCode":"    fn deserialize<R: Read>(reader: &mut R) -> io::Result<u8> {\n        reader.read_u8()\n    }\n}\n\nimpl FixedSize for u8 {\n    const SIZE_IN_BYTES: usize = 1;\n}\n\nimpl BinarySerializable for bool {\n    fn serialize<W: Write + ?Sized>(&self, writer: &mut W) -> io::Result<()> {\n        writer.write_u8(u8::from(*self))\n    }\n    fn deserialize<R: Read>(reader: &mut R) -> io::Result<bool> {\n        let val = reader.read_u8()?;\n        match val {\n            0 => Ok(false),\n            1 => Ok(true),\n            _ => Err(io::Error::new(\n                io::ErrorKind::InvalidData,\n                \"invalid bool value on deserialization, data corrupted\",\n            )),\n        }\n    }\n}\n\nimpl FixedSize for bool {\n    const SIZE_IN_BYTES: usize = 1;\n}\n\nimpl BinarySerializable for String {\n    fn serialize<W: Write + ?Sized>(&self, writer: &mut W) -> io::Result<()> {\n        let data: &[u8] = self.as_bytes();\n        BinarySerializable::serialize(&VInt(data.len() as u64), writer)?;\n        writer.write_all(data)\n    }\n","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/quickwit-oss/tantivy/blob/b5d8deb80c26924e6b007a5b1a7630f35ca64de4/common/src/serialize.rs#L206-L242","documentation":"common's Serialization trait for bool expects exactly one byte: 0 for false, 1 for true. deserialize raises InvalidData 'invalid bool value on deserialization, data corrupted' for any other byte, signaling the stream is misaligned or not written by this serializer.","triggerScenarios":"Calling bool.deserialize(reader) on a byte stream where the current position holds a value other than 0 or 1 — corrupted data, misaligned reads (skipped/extra bytes), or fields serialized by a different format.","commonSituations":"Truncated or corrupted segment files; hand-rolled writers that stored bools as e.g. 0xFF/other nonzero; version drift where field layout changed so a non-bool byte is read as bool.","solutions":["Verify file integrity (checksums) to detect corruption","Ensure serialization and deserialization call sites are symmetric and version-matched","Fix writers to emit exactly 0u8/1u8 for bools via the common serializer","Check for stream misalignment (earlier field lengths) before the bool field"],"exampleFix":"// before: custom writer\nwriter.write_u8(if flag { 0xFF } else { 0x00 })?;\n// after\nflag.serialize(writer)?; // writes 0/1 per common::Serialization","handlingStrategy":"try-catch","validationCode":"fn next_byte_is_bool(reader: &mut impl std::io::Read) -> bool {\n    // peeking variant: buffer the byte yourself and validate 0/1 before deserializing\n    let mut b = [0u8; 1];\n    reader.read_exact(&mut b).is_ok() && (b[0] == 0 || b[0] == 1)\n}","typeGuard":null,"tryCatchPattern":"match bool::deserialize(&mut reader) {\n    Err(e) if e.kind() == io::ErrorKind::InvalidData && e.to_string().contains(\"invalid bool value\") => {\n        // stream misaligned or corrupt: abort and validate file checksum\n    }\n    other => other?,\n}","preventionTips":["Always serialize bools via the common serializer (writes exactly 0/1)","Verify checksums on files before deserialization","Keep serializer layout symmetric between writer and reader versions","Check earlier field reads for misalignment when this error appears"],"tags":["io","deserialization","bool","corruption"],"backgroundTag":"data-corruption","analyzedSha":"b5d8deb80c26924e6b007a5b1a7630f35ca64de4","analyzedAt":"2026-09-05T13:20:51.521Z","contentChangedAt":"2026-09-05T13:20:51.521Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}