Code Room
Vibe codingHardvc-g339
Subject Ai code reviewLevel Senior–Staff~22 minCommon in Algorithms & data structures interviewsIndustries Telecom, Software development

Question

An AI wrote this C parser for a TLV (type-length-value) record inside a custom binary protocol. Fuzzing crashed it within seconds. Find the off-by-one / bounds bug, the exact input that triggers it, and how you'd harden it.

c
// pkt points at a buffer of total length pkt_lenint parse_tlv(const uint8_t *pkt, size_t pkt_len) {    size_t off = 0;    while (off < pkt_len) {        uint8_t  type = pkt[off];        uint16_t len  = (pkt[off+1] << 8) | pkt[off+2];        const uint8_t *val = &pkt[off + 3];        handle_tlv(type, val, len);          // reads len bytes from val        off += 3 + len;    }    return 0;}
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.