gh-156965: Make the utf-7-imap incremental decoder and stream reader stateful - #156967
Open
fedonman wants to merge 1 commit into
Open
gh-156965: Make the utf-7-imap incremental decoder and stream reader stateful#156967fedonman wants to merge 1 commit into
fedonman wants to merge 1 commit into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
utf_7_imap_decode()raisedUnicodeDecodeErrorfor a shift sequence with no terminator, and bothIncrementalDecoderandStreamReadercalled it on whole chunks, so any chunk boundary falling inside a sequence failed. It now takes afinalparameter and returns the consumed byte count instead of raising when more input may follow,IncrementalDecoderderives fromcodecs.BufferedIncrementalDecoder, andStreamReaderdecodes non-final, which is howutf_7is 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.
utf-7-imapincremental decoder and stream reader fail on split input #156965