{"record":{"id":"8a3a923b5b52af1f","repo":"vectordotdev/vector","slug":"the-slice-is-the-length-of-a-u64","errorCode":null,"errorMessage":"the slice is the length of a u64","messagePattern":"the slice is the length of a u64","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"info","filePath":"lib/vector-buffers/src/variants/disk_v2/reader.rs","lineNumber":258,"sourceCode":"            aligned_buf: AlignedVec::new(),\n            checksummer: create_crc32c_hasher(),\n            current_record_id: 0,\n            _t: PhantomData,\n        }\n    }\n\n    #[cfg_attr(test, instrument(skip(self), level = \"trace\"))]\n    async fn read_length_delimiter(\n        &mut self,\n        is_finalized: bool,\n    ) -> Result<Option<usize>, ReaderError<T>> {\n        loop {\n            let available = self.reader.buffer().len();\n            if available >= 8 {\n                let length_buf = &self.reader.buffer()[..8];\n                let length = length_buf\n                    .try_into()\n                    .expect(\"the slice is the length of a u64\");\n                self.reader.consume(8);\n\n                // By default, records cannot exceed 8MB in length, so whether our `usize` is a u32\n                // or u64, we're not going to overflow it.  While the maximum record size _can_ be\n                // changed, it's not currently exposed to users.  Even further, if it was exposed to\n                // users, it's currently a `usize`, so again, we know that we're not going to exceed\n                // 64-bit. And even further still, the writer fallibly attempts to get a `u64` of the\n                // record size based on the encoding buffer, which gives its length in `usize`, and\n                // so would fail if `usize` was larger than `u64`, meaning we at least will panic if\n                // Vector is running on a 128-bit CPU in the future, storing records that are larger\n                // than 2^64+1. :)\n                let record_len = u64::from_be_bytes(length)\n                    .try_into()\n                    .expect(\"record length should never exceed usize\");\n                return Ok(Some(record_len));\n            }\n\n            // We don't have enough bytes, so we need to fill our buffer again.","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/vectordotdev/vector/blob/3708c39b12a93212ed8b8d7510b4cc7769cb5864/lib/vector-buffers/src/variants/disk_v2/reader.rs#L240-L276","documentation":"The v2 disk buffer reader frames each record with an 8-byte big-endian length. When at least 8 bytes are buffered, the code slices exactly `buffer()[..8]` and converts that slice into `[u8; 8]` for `u64::from_be_bytes`. Because the slice is constructed with a fixed length of 8 after the `available >= 8` check, the try_into is infallible; the expect only guards against future refactors breaking that shape.","triggerScenarios":"A byte slice whose length is not exactly 8 reaching the conversion — precluded by the `available >= 8` check and the `[..8]` slice; only a code regression inside read_length_delimiter could trip it.","commonSituations":"None; the invariant is enforced two lines above the expect.","solutions":["No action possible; report upstream with the backtrace if it ever fires"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Nothing to guard: the slice length is fixed at 8 two lines above the conversion","Report any occurrence upstream — it implies a regression in read_length_delimiter"],"tags":["rust","vector","disk-buffer","invariant","slice-conversion","panic"],"backgroundTag":"slice-to-array-conversion-panic","analyzedSha":"3708c39b12a93212ed8b8d7510b4cc7769cb5864","analyzedAt":"2026-08-20T07:02:18.786Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}