bugger.
All challenges/Rusthardthe-parser-that-keeps-old-offsets-v1
THE INVESTIGATION

The parser that keeps old offsets

Rust CSV parser bug with stale field offsets

A reused CSV decoder clears its buffers but leaks field offsets from an abandoned stream.

Text and parsingState invariants

What’s going wrong

A CSV import restarts its decoder after abandoning a partial stream. The new record's bytes look correct, but field-end positions refer to the previous stream. Investigate all state with the same lifetime as the output buffer.

Stdin is at most 200 commands: FEED hex appends bytes to the current stream (- is empty), RESET discards the incomplete record, and END finalizes a pending complete or unterminated record once. Input EOF does not imply END. At most 8192 bytes are fed. Comma separates fields and LF ends records except inside double quotes. A quoted field begins with double quote at field start; inside it doubled double quotes decode to one quote. Quotes may span FEED calls. All completed/END-finalized records are otherwise valid, and END never occurs inside an unclosed quote. A reset may abandon one. Bare fields contain no quote, comma or LF; CR is ordinary data. Empty LF records represent one empty field in this exercise.

Output records concatenate their decoded field bytes without commas or quote syntax and store the cumulative exclusive byte end of each field. For fields a,bc the data is 616263 and ends are 1,3. Print a JSON array of strings datahex|end,end,... for all emitted records in order. RESET clears only the incomplete record, preserving earlier emitted records; its next field offsets must start from zero. Preserve escaped quotes, empty fields, chunk continuity and END semantics.

Expected behavior

Align every parser-state field with its owning buffer lifetime across partial reads, reset, quoted data and record completion.

Reproduction

01 New stream inherits old output offsets
FEED 7374616c65
RESET
FEED 782c790a
["7879|1,2"]
02 Ordinary record boundaries
FEED 612c620a
["6162|1,2"]
03 Quoted comma is data
FEED 22612c62222c630a
["612c6263|3,4"]

Before you begin

  • Rust strings, slices and loops
  • Use semantic round-trip and context reasoning to audit persistent parser state that survives beyond a single input call.

Need a nudge?

Reveal one investigation hint at a time. Try each clue before opening the next.

    The bug is intentional. Run the starter code to see it fail, then work toward a fix. Difficulty is provisional.
    Read-only preview
    Ready when you are
    Every fix starts with a failing test.

    Read the report, then sign in to start your investigation.