Skip to content

Commit 8ca7c00

Browse files
committed
finalBytes only once
1 parent da80e66 commit 8ca7c00

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/main/java/software/amazon/encryption/s3/internal/CipherSubscriber.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import javax.crypto.Cipher;
1212
import java.nio.ByteBuffer;
1313
import java.security.GeneralSecurityException;
14+
import java.util.concurrent.atomic.AtomicBoolean;
1415
import java.util.concurrent.atomic.AtomicLong;
1516

1617
public class CipherSubscriber implements Subscriber<ByteBuffer> {
@@ -20,6 +21,7 @@ public class CipherSubscriber implements Subscriber<ByteBuffer> {
2021
private final Long contentLength;
2122
private boolean isLastPart;
2223
private int tagLength;
24+
private AtomicBoolean finalBytesCalled = new AtomicBoolean(false);
2325

2426
private byte[] outputBuffer;
2527

@@ -139,6 +141,11 @@ public void onComplete() {
139141
}
140142

141143
public void finalBytes() {
144+
if (!finalBytesCalled.compareAndSet(false, true)) {
145+
// already called, don't repeat
146+
return;
147+
}
148+
142149
// If this isn't the last part, skip doFinal and just send outputBuffer downstream.
143150
// doFinal requires that all parts have been processed to compute the tag,
144151
// so the tag will only be computed when the last part is processed.

0 commit comments

Comments
 (0)