quickwit-oss/tantivy · error · io::Error

InvalidData

InvalidData

Error message

invalid bool value on deserialization, data corrupted

What it means

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.

Source

Thrown at common/src/serialize.rs:224

    fn deserialize<R: Read>(reader: &mut R) -> io::Result<u8> {
        reader.read_u8()
    }
}

impl FixedSize for u8 {
    const SIZE_IN_BYTES: usize = 1;
}

impl BinarySerializable for bool {
    fn serialize<W: Write + ?Sized>(&self, writer: &mut W) -> io::Result<()> {
        writer.write_u8(u8::from(*self))
    }
    fn deserialize<R: Read>(reader: &mut R) -> io::Result<bool> {
        let val = reader.read_u8()?;
        match val {
            0 => Ok(false),
            1 => Ok(true),
            _ => Err(io::Error::new(
                io::ErrorKind::InvalidData,
                "invalid bool value on deserialization, data corrupted",
            )),
        }
    }
}

impl FixedSize for bool {
    const SIZE_IN_BYTES: usize = 1;
}

impl BinarySerializable for String {
    fn serialize<W: Write + ?Sized>(&self, writer: &mut W) -> io::Result<()> {
        let data: &[u8] = self.as_bytes();
        BinarySerializable::serialize(&VInt(data.len() as u64), writer)?;
        writer.write_all(data)
    }

View on GitHub (pinned to b5d8deb80c)

Solutions

  1. Verify file integrity (checksums) to detect corruption
  2. Ensure serialization and deserialization call sites are symmetric and version-matched
  3. Fix writers to emit exactly 0u8/1u8 for bools via the common serializer
  4. Check for stream misalignment (earlier field lengths) before the bool field

Example fix

// before: custom writer
writer.write_u8(if flag { 0xFF } else { 0x00 })?;
// after
flag.serialize(writer)?; // writes 0/1 per common::Serialization
Defensive patterns

Strategy: try-catch

Validate before calling

fn next_byte_is_bool(reader: &mut impl std::io::Read) -> bool {
    // peeking variant: buffer the byte yourself and validate 0/1 before deserializing
    let mut b = [0u8; 1];
    reader.read_exact(&mut b).is_ok() && (b[0] == 0 || b[0] == 1)
}

Try / catch

match bool::deserialize(&mut reader) {
    Err(e) if e.kind() == io::ErrorKind::InvalidData && e.to_string().contains("invalid bool value") => {
        // stream misaligned or corrupt: abort and validate file checksum
    }
    other => other?,
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of quickwit-oss/tantivy@b5d8deb80c (2026-09-05). Data as JSON: /api/errors/f9c55773f4527421. Report an issue: GitHub.