aajisaka commented on code in PR #58909:
URL: https://github.com/apache/spark/pull/58909#discussion_r4553552238
##########
common/network-common/src/main/java/org/apache/spark/network/crypto/GcmTransportCipher.java:
##########
@@ -212,7 +213,7 @@ public boolean release(int decrement) {
@Override
public long transferTo(WritableByteChannel target, long position)
throws IOException {
- int transferredThisCall = 0;
+ long transferredThisCall = 0;
Review Comment:
Fixed by
https://github.com/apache/spark/commit/7512339b1f18b8b748a749cfb9b8b4a4befead33
Implemented `testTransferToReturnsLargeByteCount`
##########
common/network-common/src/test/java/org/apache/spark/network/crypto/GcmAuthEngineSuite.java:
##########
@@ -570,6 +573,60 @@ public void testSplitLengthPrefix() throws Exception {
}
}
+ @Test
+ public void testCiphertextLengthLargerThanMaxInt() throws Exception {
+ TransportConf gcmConf = getConf(2, false);
+ try (AuthEngine client = new AuthEngine("appId", "secret", gcmConf);
+ AuthEngine server = new AuthEngine("appId", "secret", gcmConf)) {
+ AuthMessage clientChallenge = client.challenge();
+ AuthMessage serverResponse = server.response(clientChallenge);
+ client.deriveSessionCipher(clientChallenge, serverResponse);
+ GcmTransportCipher cipher = (GcmTransportCipher) server.sessionCipher();
+ GcmTransportCipher.DecryptionHandler decryptionHandler =
cipher.getDecryptionHandler();
+ AesGcmHkdfStreaming streaming = cipher.getAesGcmHkdfStreaming();
+
+ // remaining ciphertext length is Integer.MAX_VALUE + 1,
+ // which becomes Integer.MIN_VALUE when cast to int.
+ long expectedLength = (long) GcmTransportCipher.LENGTH_HEADER_BYTES +
+ streaming.getHeaderLength() + Integer.MAX_VALUE + 1L;
+ StreamSegmentEncrypter encrypter = streaming.newStreamSegmentEncrypter(
+ Longs.toByteArray(expectedLength));
+ ByteBuffer header = encrypter.getHeader();
+ ByteBuf ciphertext =
Unpooled.buffer(GcmTransportCipher.LENGTH_HEADER_BYTES +
+ header.remaining() + 1)
+ .writeLong(expectedLength)
+ .writeBytes(header)
+ .writeByte(0);
+ ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
+
+ decryptionHandler.channelRead(ctx, ciphertext);
+
+ verify(ctx, never()).fireChannelRead(any());
Review Comment:
Fixed by
https://github.com/apache/spark/commit/7512339b1f18b8b748a749cfb9b8b4a4befead33
Now the test encrypts real segments
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]