Skip to content

gh-156965: Make the utf-7-imap incremental decoder and stream reader stateful - #156967

Open
fedonman wants to merge 1 commit into
python:mainfrom
fedonman:fix-utf7-imap-incremental-decoder
Open

gh-156965: Make the utf-7-imap incremental decoder and stream reader stateful#156967
fedonman wants to merge 1 commit into
python:mainfrom
fedonman:fix-utf7-imap-incremental-decoder

Conversation

@fedonman

@fedonman fedonman commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

utf_7_imap_decode() raised UnicodeDecodeError for a shift sequence with no terminator, and both IncrementalDecoder and StreamReader called it on whole chunks, so any chunk boundary falling inside a sequence failed. It now takes a final parameter and returns the consumed byte count instead of raising when more input may follow, IncrementalDecoder derives from codecs.BufferedIncrementalDecoder, and StreamReader decodes non-final, which is how utf_7 is wired. The stateless decoder still raises on a truncated sequence.

This covers the decoder. The incremental encoder breaks the same rule more mildly, joining to different bytes than one shot for the same text, and the remedy there is a choice between buffering the pending run and documenting the limit, so it is left alone.

There is no NEWS entry because the codec is new in 3.16 and unreleased, so no user could hit this.

…eader stateful

utf_7_imap_decode() raised on a shift sequence with no terminator, so the
incremental decoder and the stream reader, which both called it on whole
chunks, failed whenever a chunk boundary fell inside a sequence.  Give it
a final parameter that reports the consumed byte count instead, and take
the buffering from codecs.BufferedIncrementalDecoder, as utf_7 does.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant