{"record":{"id":"b838990177c8fdc5","repo":"cloudflare/quiche","slug":"value-is-too-large-for-varint","errorCode":null,"errorMessage":"value is too large for varint","messagePattern":"value is too large for varint","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"octets/src/lib.rs","lineNumber":579,"sourceCode":"            2 => {\n                let buf = self.put_u16(v as u16)?;\n                buf[0] |= 0x40;\n                buf\n            },\n\n            4 => {\n                let buf = self.put_u32(v as u32)?;\n                buf[0] |= 0x80;\n                buf\n            },\n\n            8 => {\n                let buf = self.put_u64(v)?;\n                buf[0] |= 0xc0;\n                buf\n            },\n\n            _ => panic!(\"value is too large for varint\"),\n        };\n\n        Ok(buf)\n    }\n\n    /// Reads `len` bytes from the current offset without copying and advances\n    /// the buffer.\n    pub fn get_bytes(&mut self, len: usize) -> Result<Octets<'_>> {\n        if self.cap() < len {\n            return Err(BufferTooShortError);\n        }\n\n        let out = Octets {\n            buf: &self.buf[self.off..self.off + len],\n            off: 0,\n        };\n\n        self.off += len;","sourceCodeStart":561,"sourceCodeEnd":597,"githubUrl":"https://github.com/cloudflare/quiche/blob/9f96daa2c22a4468b0036fb0a0a3894eee6498b8/octets/src/lib.rs#L561-L597","documentation":"octets panics in put_varint_with_len when the value to encode does not fit in the requested varint length. QUIC varints support 1/2/4/8-byte encodings with maxima of 63, 16383, 2^30-1, and 2^62-1; the panic arm is an internal exhaustive-match fallback reached only if the value exceeds even the 8-byte encoding (>= 2^62) or len was not one of the supported sizes. put_varint guarantees a valid len, so in practice only values >= 2^62 hit this.","triggerScenarios":"Calling put_varint with a u64 >= 2^62 (the match falls through to the 8-branch otherwise), or calling put_varint_with_len directly with a length other than 1/2/4/8 combined with an out-of-range value.","commonSituations":"Encoding untrusted or corrupted counters (e.g. huge IDs, offsets, lengths parsed from bad input) into QUIC frames; math bugs producing u64::MAX-like values; fuzz-generated inputs.","solutions":["Validate the value before encoding: ensure v < (1u64 << 62) (and fits the chosen len: <1<<6, <1<<14, <1<<30, <1<<62).","Clamp or reject upstream values that can exceed the QUIC varint range instead of encoding them.","If calling put_varint_with_len directly, restrict len to 1, 2, 4, or 8 and size it to the value."],"exampleFix":"// before\nb.put_varint(huge_value)?;\n// after\nassert!(huge_value < (1u64 << 62), \"value too large for QUIC varint\");\nb.put_varint(huge_value)?;","handlingStrategy":"validation","validationCode":"fn fits_varint(v: u64) -> bool { v < (1u64 << 62) }\n// call site\nassert!(fits_varint(v), \"value {} exceeds QUIC varint range\", v);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Range-check any value parsed from untrusted input before varint encoding.","Remember the per-length maxima: 63, 16383, 2^30-1, 2^62-1."],"tags":["quiche","octets","varint","encoding"],"backgroundTag":"value-out-of-range","analyzedSha":"9f96daa2c22a4468b0036fb0a0a3894eee6498b8","analyzedAt":"2026-09-08T11:27:09.536Z","contentChangedAt":"2026-09-08T11:27:09.536Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}