StreamingAeadSeekableDecryptingChannel.read() never returns -1 — infinite CPU spin / hang on empty or truncated ciphertexts
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 74/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- java
- Ambito
- cryptography
Direzione di ricerca
Start in StreamingAeadSeekableDecryptingChannel.java, focusing on read(), reachedEnd(), and the fill loop; review StreamingTestUtil to understand why EOF is not covered. Add regression coverage for empty, boundary, and truncated ciphertexts across AES-GCM-HKDF and AES-CTR-HMAC, and verify reads return -1 rather than repeatedly returning 0.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
tink-java: StreamingAeadSeekableDecryptingChannel.read() never returns -1 — infinite CPU spin / hang on empty or truncated ciphertexts
Repo: tink-crypto/tink-java (OT0)
Summary
StreamingAeadSeekableDecryptingChannel (returned by the public
StreamingAead.newSeekableDecryptingChannel API) violates the
SeekableByteChannel contract: read(ByteBuffer) never returns -1 at
end-of-stream. Callers using the universal idiom spin forever burning CPU, and
Channels.newInputStream(ch).readAllBytes() / transferTo never return.
Verified against HEAD (810d752), PoC output:
valid empty-plaintext ciphertext: 56 bytes
HANG: valid-empty (seg 64): read() returned 0 one-million times (11 ms of CPU spin), never -1
HANG: valid-empty (seg 64): Channels.newInputStream(...).readAllBytes() did not return within 3 s
HANG: truncated-56B (seg 64): read() returned 0 one-million times, never -1
Affects both AES-GCM-HKDF and legacy AES-CTR-HMAC (shared plumbing).
Root cause
read() returns 0 whenever read == 0 && !reachedEnd()
(StreamingAeadSeekableDecryptingChannel.java). reachedEnd() (line 282) requires
isCurrentSegmentDecrypted && currentSegmentNr == numberOfSegments-1 && plaintextSegment.remaining() == 0. When plaintextSize == 0 — which happens for a
valid empty-plaintext ciphertext, and for attacker-truncated ciphertexts whose
computed size fills complete segments — the fill loop
while (dst.remaining() > 0 && plaintextPosition < plaintextSize) never runs, no
segment is ever decrypted, so reachedEnd() is permanently false and read() loops
on 0 forever.
Note the impact split:
- No attacker needed: encrypt an empty stream with the library itself, then read
it through the seekable channel — the service thread hangs. A valid
round-trip that hangs is a correctness bug on its own. - Attacker-controlled: decrypting an untrusted/truncated file via
newSeekableDecryptingChannelhangs the thread (truncation scan of a 70-byte
plaintext hangs at offsets 56/80/144 for segment size 64).
tink-go's reader handles the identical 56-byte ciphertext correctly (io.ReadAll
terminates — verified), so this is Java-specific. The existing test suite misses it
because StreamingTestUtil allocates plaintext.length-sized buffers and never
reads to EOF.
Fix direction
When the fill loop makes no progress and plaintextPosition >= plaintextSize (or
ciphertext is exhausted), decrypt the final (possibly empty) segment so
reachedEnd() becomes true and read() returns -1. Reproducer and a table-driven
regression test (empty, 0/1/±tag-boundary, truncated lengths) are ready to send.
Verified against HEAD (810d752). Reproducer harness output above was produced with the AES-GCM-HKDF keyset at segment size 64; AES-CTR-HMAC shares the plumbing and behaves identically.
- Lingua principale
- Java
- Stelle
- 308
- Fork
- 41
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di tink-crypto/tink-java
-
java.lang.NoSuchMethodError: java.nio.ByteBuffer.position(I)Ljava/nio/ByteBuffer; in InsecureNonceChaCha20Poly1305Base on JDK8Forse già presa @Sineaggi l’ha presa 155 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 48/100
tink-crypto/tink-java#68 · 13 commenti ·
-
Support registering custom key managers for user-defined primitives (or provide a migration path)Forse di nuovo libera @tholenst l’ha presa 236 giorni fa e non c’è nessuna pull request aperta. Aperta
tink-crypto/tink-java#67 · 5 commenti · 1 assegnatario ·
-
p3
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
tink-crypto/tink-java#66 · 3 commenti ·
-
p3
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
tink-crypto/tink-java#41 · 1 commento ·
-
p3
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
tink-crypto/tink-java#26 · 14 commenti · 5 reazioni ·
Tutte le issue di tink-crypto/tink-java
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
PhasetransCrystal/FPSMatch#47 ·
I maintainer di solito rispondono entro 1 giorno
-
Remove unactionable info logApertabug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 76/100
apache/maven-toolchains-plugin#205 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
I maintainer di solito rispondono entro 1 giorno
-
[Bug] Dated CSV export filenames use the UTC day rather than the operator dayForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
apache/rocketmq-dashboard#6896 ·
I maintainer di solito rispondono entro 3 giorni