fix: handle Gmail raw response streams correctly - #3271
Draft
DenBond7 wants to merge 1 commit into
Draft
Conversation
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.
Description
Gmail returns raw MIME messages and attachment data as Base64URL values inside JSON responses. We use custom
FilterInputStreamimplementations to skip the JSON prefix and stop reading at the closing quote.The current implementations do not correctly handle every valid
InputStreamread pattern.Problems
read()is not overridden, so byte-by-byte consumers can receive the closing quote and trailing JSON.read(byte[], off, len)searches the entire buffer instead of only the newly read range. Existing buffer content containing"can therefore cause premature end-of-stream.off.0for a non-empty request, violating theInputStreamcontract.skip()call, althoughInputStream.skip()may consume fewer bytes than requested.These issues can cause MIME messages or attachments to be truncated, incorrectly decoded, or contaminated with trailing JSON. The behavior depends on the delegate stream, buffer contents, offsets, and read chunk size.
Steps to reproduce
Byte-by-byte read
{ "raw": "YWJjZA==" }GMailRawMIMEMessageFilterInputStream.read()one byte at a time.Reused buffer with offset
read(buffer, nonZeroOffset, length).Partial prefix skip
skip()method consumes only one byte per call.GMailRawAttachmentFilterInputStream.Expected behavior
read()andread(byte[], off, len)behave consistently.-1.InputStreamcontract.EOFException.close #3270
Tests (delete all except exactly one):
To be filled by reviewers
I have reviewed that this PR... (tick whichever items you personally focused on during this review):