{"record":{"id":"44d8ccc6a8596793","repo":"databendlabs/databend","slug":"index-out-of-range","errorCode":null,"errorMessage":"index out of range","messagePattern":"index out of range","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/common/io/src/bitmap/reader.rs","lineNumber":245,"sourceCode":"            Ok(BitmapReader {\n                prefix,\n                containers,\n                buf: &buf[..size],\n            })\n        }\n    }\n\n    pub fn containers(&self) -> usize {\n        self.containers as usize\n    }\n\n    pub fn prefix(&self) -> u32 {\n        self.prefix\n    }\n\n    pub fn description(&self, i: usize) -> io::Result<Description> {\n        if i >= self.containers() {\n            return Err(Error::new(ErrorKind::InvalidInput, \"index out of range\"));\n        }\n\n        let mut desc_buf = &self.buf[12 + i * DESCRIPTION_BYTES..];\n        let prefix = desc_buf.read_u16::<LittleEndian>()?;\n        let cardinality = desc_buf.read_u16::<LittleEndian>()?;\n        Ok(Description {\n            prefix,\n            cardinality,\n        })\n    }\n\n    pub fn bitmap_buf(&self) -> &[u8] {\n        &self.buf[4..]\n    }\n\n    pub(crate) fn container_offset(&self, i: usize) -> io::Result<usize> {\n        if i >= self.containers() {\n            return Err(Error::other(\"index out of range\"));","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/common/io/src/bitmap/reader.rs#L227-L263","documentation":"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.","triggerScenarios":"Calling description(i) with i >= containers(), e.g. iterating with a wrong upper bound or hardcoding an index without checking containers().","commonSituations":"Custom iteration code over bitmap containers that assumes a fixed count; stale container counts after the underlying buffer changed.","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."],"exampleFix":"// before\nlet desc = reader.description(i)?;\n\n// after\nif i < reader.containers() {\n    let desc = reader.description(i)?;\n}","handlingStrategy":"validation","validationCode":"if i >= reader.containers() {\n    return Err(anyhow!(\"container index {} out of range\", i));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["bitmap","index","rust","bounds-check"],"backgroundTag":"index-out-of-range","analyzedSha":"288d84d76e20a2f8f7173bda9691eb6ece301aa9","analyzedAt":"2026-09-11T11:29:36.208Z","contentChangedAt":"2026-09-11T11:29:36.208Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}