Code Room
Vibe codingHard
Question
An AI wrote this Rust function to read a length-prefixed blob from a stream into a pre-sized Vec. It compiles cleanly and looks idiomatic. Identify the denial-of-service / integer bug, the packet that triggers it, and the fix.
fn read_blob<R: Read>(r: &mut R) -> io::Result<Vec<u8>> { let mut len_buf = [0u8; 4]; r.read_exact(&mut len_buf)?; let len = u32::from_be_bytes(len_buf) as usize; let mut buf = vec![0u8; len]; // pre-allocate len bytes r.read_exact(&mut buf)?; Ok(buf)}What a strong answer looks like
Treat the AI’s output as a draft to verify, not an answer to trust. Name the specific flaw and the input that triggers it, say how you’d catch it — tests, edge cases, reading critically — and how you’d re-prompt or decompose to get it right.
Learn the concepts
Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.
Run or narrate your approach, then ask the coach.