Menu

Why a parser cursor has to stay failed after the first refusal
📰

Why a parser cursor has to stay failed after the first refusal

DEV Community: cpp·polycratia·about 1 month ago
#ChSQcrAS
#devtocpp#devto#dev#cursor#offset_
Long article (1794 words) — no AI summary yet.
Reading 0:00
15s threshold

A C++ parser for a binary format fails in one of two ways: it trusts a length field and reads past the end of its buffer, or it has a bounds check on every single read and nobody keeps that up. The second failure is the more interesting one, because people agree with the discipline right up until they skip it. A record header is ten reads, and honest per-read checking means you write the same conditional ten times to reach one return std::nullopt .

I have spent most of the last decade on payment and crypto systems, so most of my parsing work has been on framed messages arriving off a socket from something I do not control. The conclusion I keep arriving at is not more checks. It is a cursor that stays failed once it has refused anything, so the ten checks collapse into one question you ask at the end.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.