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
- Check containers() before calling description(i) and clamp/stop the loop at that bound.
- Use the library's iterator/lookup helpers (container, find_container) instead of raw indices.
- 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
- Always bound loops by reader.containers().
- Prefer the library's container/find_container helpers over raw indices.
- Re-derive the reader when the underlying buffer changes.
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
- not implemented
- hybrid bitmap small set size overflow
- data is truncated or invalid
- container offset exceeds bitmap data
- Unsupported format for
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)