Code Room
Vibe codingMediumvc-g352
Subject Ai code reviewLevel Mid–Senior~18 minCommon in Algorithms & data structures interviewsIndustries Telecom, Software development

Question

An AI wrote this Go code to verify a packet's trailing checksum before processing it. It accepts every valid packet in tests but also lets corrupted ones through. Find the validation bug, the packet that slips past, and the fix.

go
func verify(pkt []byte) bool {    if len(pkt) < 2 {        return false    }    body := pkt[:len(pkt)-2]    got := binary.BigEndian.Uint16(pkt[len(pkt)-2:])    var sum uint16    for _, b := range body {        sum += uint16(b)    }    return sum == got       // checksum is sum of body bytes}
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.

Describe your solution

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.