fix(streamingaead): return -1 at EOF on empty seekable plaintext - #81
Open
arimu1 wants to merge 1 commit into
Open
fix(streamingaead): return -1 at EOF on empty seekable plaintext#81arimu1 wants to merge 1 commit into
arimu1 wants to merge 1 commit into
Conversation
When plaintext size is zero, read() never decrypted the last segment so reachedEnd() stayed false and callers spun on 0 forever. Decrypt the final segment when at end-of-plaintext with no bytes transferred. Fixes tink-crypto#79
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.
Summary
StreamingAeadSeekableDecryptingChannel.read()could return0forever whenplaintextSize == 0because no segment was decrypted andreachedEnd()never became true (fixes infinite spin on valid empty ciphertext and similar EOF cases).-1is returned perSeekableByteChannelcontract.b/390077226workarounds in seekable decrypt tests; empty-plaintext vectors now assert-1at EOF like non-empty streams.Fixes #79
Test plan
JAVA_HOME=…/jdk-21.0.12+8 bazel test //src/test/java/com/google/crypto/tink/streamingaead:AesGcmHkdfStreamingKeyManagerTest //src/test/java/com/google/crypto/tink/streamingaead:AesCtrHmacStreamingKeyManagerTest --test_output=errors— 2/2 passed