Skip to content

fix(streamingaead): return -1 at EOF on empty seekable plaintext - #81

Open
arimu1 wants to merge 1 commit into
tink-crypto:mainfrom
arimu1:fix/79-seekable-read-eof
Open

fix(streamingaead): return -1 at EOF on empty seekable plaintext#81
arimu1 wants to merge 1 commit into
tink-crypto:mainfrom
arimu1:fix/79-seekable-read-eof

Conversation

@arimu1

@arimu1 arimu1 commented Sep 12, 2026

Copy link
Copy Markdown

Summary

  • StreamingAeadSeekableDecryptingChannel.read() could return 0 forever when plaintextSize == 0 because no segment was decrypted and reachedEnd() never became true (fixes infinite spin on valid empty ciphertext and similar EOF cases).
  • When no bytes are transferred and the read position is at or past the computed plaintext size, decrypt the final segment so EOF is detected and -1 is returned per SeekableByteChannel contract.
  • Remove stale b/390077226 workarounds in seekable decrypt tests; empty-plaintext vectors now assert -1 at 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=errors2/2 passed

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StreamingAeadSeekableDecryptingChannel.read() never returns -1 — infinite CPU spin / hang on empty or truncated ciphertexts

1 participant