Files
swift-nio-imap/Sources/NIOIMAP
Daniel Eggert 70aa6bea44 Throw NoForwardProgress when parsing stops consuming
A parser bug that stops consuming input used to spin forever on peer
bytes: extractBytes looped with take == 0 once the cursor invariant
broke, the repetition combinators looped on an element that matched
empty, and IMAPInputProcessor looped on a decoder returning messages
without consuming. Each now throws the new public NoForwardProgress
(public init, so a decoder driver outside the library can throw it as
IMAPInputProcessor does), which no backtracking point treats as "did
not match":

- extractBytes throws when the head is empty but bytes remain; the
  scans stop when advancing their walker consumes nothing. Both also
  assertionFailure, and a debug-only check in advance compares what it
  consumed against what was visible before, so tests trap at the bug.
- forEachRepetition backs every repetition combinator and the search
  sources list; the other hand-written grammar loops check progress per
  iteration (requireProgress).
- IMAPInputProcessor allows 4 messages in a row without progress; the
  parsers emit at most 2 (commands) and 1 (responses), pinned by tests
  that run the real decoders.

Catch sites that took any error for a mismatch now catch ParserError
only, or let NoForwardProgress through: mailbox list flags, the body
and section fallbacks, and the run-away literal check. (#885 already
narrowed the tagged extension catches.)

Behavior changes: those loops now report a list cut short by the end of
the input as IncompleteMessage instead of returning what they had. Mostly
not observable through the stream parsers, which retry; a flag list
split mid-flag gets a split-at-every-byte case. The stream parser docs
tell callers who drive them directly to bound results without progress,
as the handlers do.

Reviewer focus: the catch sites, and the limit's reasoning in
IMAPInputProcessor.maximumMessagesWithoutProgress.
2026-11-24 09:48:27 +09:00
..
2026-11-24 09:48:20 +09:00
2020-05-18 15:49:40 +01:00