{"record":{"id":"525b89c1533c53ed","repo":"GitoxideLabs/gitoxide","slug":"bit-word-count-exceeds-u32-max","errorCode":null,"errorMessage":"bit word count exceeds u32::MAX","messagePattern":"bit word count exceeds u32::MAX","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix-bitmap/src/ewah.rs","lineNumber":78,"sourceCode":"                })\n                .collect();\n            let num_bits = bits.len().try_into().ok()?;\n\n            Some(Vec {\n                num_bits,\n                bits: std::iter::once((literal_words.len() as u64) << (1 + RLW_RUNNING_BITS))\n                    .chain(literal_words)\n                    .collect(),\n                rlw: 0,\n            })\n        }\n\n        /// Write the bitmap as EWAH bytes to `out`.\n        ///\n        /// These bytes can be parsed again with [`decode()`](super::decode()).\n        pub fn write_to(&self, out: &mut impl std::io::Write) -> std::io::Result<()> {\n            let len: u32 = self.bits.len().try_into().map_err(|_| {\n                std::io::Error::new(std::io::ErrorKind::InvalidInput, \"bit word count exceeds u32::MAX\")\n            })?;\n            let rlw: u32 = self.rlw.try_into().map_err(|_| {\n                std::io::Error::new(\n                    std::io::ErrorKind::InvalidInput,\n                    \"run length word offset exceeds u32::MAX\",\n                )\n            })?;\n\n            out.write_all(&self.num_bits.to_be_bytes())?;\n            out.write_all(&len.to_be_bytes())?;\n            for word in &self.bits {\n                out.write_all(&word.to_be_bytes())?;\n            }\n            out.write_all(&rlw.to_be_bytes())\n        }\n\n        /// Call `f(index)` for each bit that is true, given the index of the bit that identifies it uniquely within the bit array.\n        /// If `f` returns `None` the iteration will be stopped and `None` is returned.","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix-bitmap/src/ewah.rs#L60-L96","documentation":"`EwahBitmap::write_to` serializes the bitmap's word list, and the EWAH format stores the word count as a `u32`. When the bitmap contains more than `u32::MAX` (~4.29 billion) words, the count cannot be encoded, so `write_to` returns an `io::Error` of kind `InvalidInput` instead of writing a corrupt file.","triggerScenarios":"Calling `write_to` on a bitmap whose `bits` vector length exceeds `u32::MAX`, i.e. an absurdly large bitmap (each word covers 64 bits, so >2^38 bits).","commonSituations":"Practically only reached with unbounded accumulation into a bitmap from a huge or buggy input source, or on 64-bit systems where memory allows constructing such a vector.","solutions":["Split the bitmap into chunks smaller than u32::MAX words and write each separately","Check `bitmap.bits.len() <= u32::MAX` before writing and fail early with your own error","Investigate upstream logic that grows the bitmap unboundedly; real Git index bitmaps never approach this size"],"exampleFix":"// before\nbitmap.write_to(&mut out)?;\n// after\nassert!(bitmap.bits.len() <= u32::MAX as usize, \"bitmap too large for EWAH\");\nbitmap.write_to(&mut out)?;","handlingStrategy":"validation","validationCode":"if bitmap.bits.len() > u32::MAX as usize {\n    return Err(io::Error::new(io::ErrorKind::InvalidInput, \"bitmap too large\"));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Cap bitmap size at construction time","Chunk very large bitmaps before serialization","Treat word counts near u32::MAX as a bug indicator"],"tags":["bitmap","serialization","limit"],"backgroundTag":"value-out-of-range","analyzedSha":"e73179060badf27222d790981fac3f84c1830a7e","analyzedAt":"2026-09-08T11:26:50.865Z","contentChangedAt":"2026-09-08T11:26:50.865Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}