fix: do not signal onComplete when the incoming buffer length is less than the cipher block#209
Merged
Conversation
added 2 commits
March 15, 2024 11:45
… than the cipher block
imabhichow
reviewed
Mar 18, 2024
josecorella
pushed a commit
that referenced
this pull request
Mar 21, 2024
## [3.1.2](v3.1.1...v3.1.2) (2024-03-21) ### Fixes * create clients only if necessary ([#187](#187)) ([ea0c0c7](ea0c0c7)) * do not signal onComplete when the incoming buffer length is less than the cipher block ([#209](#209)) ([8b1a686](8b1a686)) ### Maintenance * fix dependabot.yml ([#190](#190)) ([5ee8b08](5ee8b08)) * modify range to allow queries specifying only the start index ([#184](#184)) ([765b9c6](765b9c6)) * **README:** detail no unencrypted pass through ([#189](#189)) ([576ea66](576ea66)), closes [#186](#186) [/github.com//issues/186#issuecomment-1973016669](https://github.com/aws//github.com/aws/amazon-s3-encryption-client-java/issues/186/issues/issuecomment-1973016669)
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.
Issue #, if available: #185
Description of changes: The current implementation of the
CipherSubscriberincorrectly assumes that the incomingByteBufferwill only contain fewer bytes than the block cipher when it is the final block. In fact, the incomingByteBuffercould have fewer bytes in cases where e.g. the networking conditions are poor. As a result, theCipherSubscribermay erroneously callonComplete()partway through the operation, which then fails due to contentLength mismatch. Additionally, as pointed out in #185, theCipherSubscribermay instead throw a NPE whenamountToReadFromByteBufferis greater than the block size.This PR fixes both bugs by instead checking if the
contentReadis equal tocontentLengthbefore signalingonComplete. If the data has not been fully read, then theCipherSubscriberpasses an empty array to avoid blocking such that subsequentonNext()invocations will fill up the cipher's underlying buffer until it has enough bytes to process a full block.Also, adds a test which was failing before this change. It requires specifying BouncyCastle as the JCE Provider as other providers (SunJCE, ACCP) return empty buffers instead of
null.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Check any applicable: