Skip to content

Commit 74a69df

Browse files
committed
Remove premature optimization
Remove code that avoids extra allocations but that could lead to an exception if bytesNeeded > hard-coded array length JAVA-3071
1 parent 00dfda1 commit 74a69df

File tree

1 file changed

+2
-3
lines changed
  • driver-sync/src/main/com/mongodb/client/internal

1 file changed

+2
-3
lines changed

driver-sync/src/main/com/mongodb/client/internal/Crypt.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,12 +298,11 @@ private void decryptKeys(final MongoCryptContext cryptContext) {
298298
private void decryptKey(final MongoKeyDecryptor keyDecryptor) {
299299
InputStream inputStream = keyManagementService.stream(keyDecryptor.getHostName(), keyDecryptor.getMessage());
300300
try {
301-
byte[] bytes = new byte[4096];
302-
303301
int bytesNeeded = keyDecryptor.bytesNeeded();
304302

305303
while (bytesNeeded > 0) {
306-
int bytesRead = inputStream.read(bytes, 0, bytesNeeded);
304+
byte[] bytes = new byte[bytesNeeded];
305+
int bytesRead = inputStream.read(bytes, 0, bytes.length);
307306
keyDecryptor.feed(ByteBuffer.wrap(bytes, 0, bytesRead));
308307
bytesNeeded = keyDecryptor.bytesNeeded();
309308
}

0 commit comments

Comments
 (0)