databendlabs/databend · error

index out of range

Error message

index out of range

What it means

BitmapReader::description(i) returns the i-th container description (prefix + cardinality). If i is greater than or equal to the total container count (self.containers()), the index is out of range and an InvalidInput io error is raised before reading the description table.

Solutions

  1. Check containers() before calling description(i) and clamp/stop the loop at that bound.
  2. Use the library's iterator/lookup helpers (container, find_container) instead of raw indices.
  3. Re-decode the reader if the buffer was replaced or truncated after construction.

Example fix

// before
let desc = reader.description(i)?;

// after
if i < reader.containers() {
    let desc = reader.description(i)?;
}
Defensive patterns

Strategy: validation

Validate before calling

if i >= reader.containers() {
    return Err(anyhow!("container index {} out of range", i));
}

Prevention

When it happens

Trigger: Calling description(i) with i >= containers(), e.g. iterating with a wrong upper bound or hardcoding an index without checking containers().

Common situations: Custom iteration code over bitmap containers that assumes a fixed count; stale container counts after the underlying buffer changed.

Related errors


AI-assisted analysis of databendlabs/databend@288d84d76e (2026-09-11). Data as JSON: /api/errors/44d8ccc6a8596793. Report an issue: GitHub.

Appendix: source

Thrown at src/common/io/src/bitmap/reader.rs:245

            Ok(BitmapReader {
                prefix,
                containers,
                buf: &buf[..size],
            })
        }
    }

    pub fn containers(&self) -> usize {
        self.containers as usize
    }

    pub fn prefix(&self) -> u32 {
        self.prefix
    }

    pub fn description(&self, i: usize) -> io::Result<Description> {
        if i >= self.containers() {
            return Err(Error::new(ErrorKind::InvalidInput, "index out of range"));
        }

        let mut desc_buf = &self.buf[12 + i * DESCRIPTION_BYTES..];
        let prefix = desc_buf.read_u16::<LittleEndian>()?;
        let cardinality = desc_buf.read_u16::<LittleEndian>()?;
        Ok(Description {
            prefix,
            cardinality,
        })
    }

    pub fn bitmap_buf(&self) -> &[u8] {
        &self.buf[4..]
    }

    pub(crate) fn container_offset(&self, i: usize) -> io::Result<usize> {
        if i >= self.containers() {
            return Err(Error::other("index out of range"));

View on GitHub (pinned to 288d84d76e)