{"record":{"id":"c9e2b262bc6e7e30","repo":"uutils/coreutils","slug":"memory-allocation-failed","errorCode":null,"errorMessage":"memory allocation failed","messagePattern":"memory allocation failed","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"src/uucore/src/lib/features/sum.rs","lineNumber":83,"sourceCode":"    fn output_bits(&self) -> usize;\n    fn output_bytes(&self) -> usize {\n        self.output_bits().div_ceil(8)\n    }\n\n    fn result(&mut self) -> io::Result<DigestOutput> {\n        let mut buf: Vec<u8> = Vec::new();\n        try_reserve_zeroed(&mut buf, self.output_bytes())?;\n        self.hash_finalize(&mut buf);\n        Ok(DigestOutput::Vec(buf))\n    }\n}\n\n/// Grows `buf` to `len` zero bytes, returning an [`io::Error`] with\n/// [`io::ErrorKind::OutOfMemory`] instead of aborting the process if the\n/// allocation can't be satisfied (e.g. an absurdly large `--length`, #12869).\nfn try_reserve_zeroed(buf: &mut Vec<u8>, len: usize) -> io::Result<()> {\n    buf.try_reserve_exact(len)\n        .map_err(|e| io::Error::new(io::ErrorKind::OutOfMemory, e))?;\n    buf.resize(len, 0);\n    Ok(())\n}\n\n/// first element of the tuple is the blake2b state\n/// second is the number of output bits\npub struct Blake2b {\n    digest: blake2b_simd::State,\n    bit_size: usize,\n}\n\nimpl Blake2b {\n    pub const DEFAULT_BYTE_SIZE: usize = 64;\n    pub const DEFAULT_BIT_SIZE: usize = Self::DEFAULT_BYTE_SIZE * 8;\n\n    /// Return a new Blake2b instance with a custom output bytes length\n    pub fn with_output_bytes(output_bytes: usize) -> Self {\n        debug_assert!(","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/uutils/coreutils/blob/0b77ced48502a5f80c51dfa827af7e69f3687053/src/uucore/src/lib/features/sum.rs#L65-L101","documentation":"Error \"memory allocation failed\" thrown in uutils/coreutils.","triggerScenarios":"Occurs when a memory allocation in the sum (hash) feature fails, typically under memory pressure.","commonSituations":"Hashing very large inputs or running on systems with exhausted memory or restrictive limits.","solutions":["Free system memory or process smaller inputs so the allocation can succeed.","Check for integer overflow in the size computation that produced the huge allocation."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0b77ced48502a5f80c51dfa827af7e69f3687053","analyzedAt":"2026-08-19T21:43:27.871Z","contentChangedAt":"2026-08-19T21:43:27.871Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}