This repository was archived by the owner on Mar 23, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 135
fix(jdbc): various perf improvements #4114
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,7 @@ | |
| import java.awt.Desktop; | ||
| import java.io.BufferedReader; | ||
| import java.io.ByteArrayInputStream; | ||
| import java.io.FileInputStream; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.io.InputStreamReader; | ||
|
|
@@ -331,11 +332,11 @@ private static boolean isFileExists(String filename) { | |
| } | ||
| } | ||
|
|
||
| private static boolean isJson(String value) { | ||
| private static boolean isJson(byte[] value) { | ||
| try { | ||
| // This is done this way to ensure strict Json parsing | ||
| // https://github.com/google/gson/issues/1208#issuecomment-2120764686 | ||
| InputStream stream = new ByteArrayInputStream(value.getBytes()); | ||
| InputStream stream = new ByteArrayInputStream(value); | ||
| InputStreamReader reader = new InputStreamReader(stream); | ||
| JsonReader jsonReader = new JsonReader(reader); | ||
| jsonReader.setStrictness(Strictness.STRICT); | ||
|
|
@@ -365,17 +366,21 @@ private static GoogleCredentials getGoogleServiceAccountCredentials( | |
|
|
||
| final String keyPath = pvtKeyPath != null ? pvtKeyPath : pvtKey; | ||
| PrivateKey key = null; | ||
| InputStream stream = null; | ||
| byte[] keyBytes = pvtKey != null ? pvtKey.getBytes() : null; | ||
|
|
||
| if (isFileExists(keyPath)) { | ||
| key = privateKeyFromP12File(keyPath, p12Password); | ||
| if (key == null) { | ||
| stream = Files.newInputStream(Paths.get(keyPath)); | ||
| } | ||
| } else if (isJson(pvtKey)) { | ||
| stream = new ByteArrayInputStream(pvtKey.getBytes()); | ||
| InputStream stream = new FileInputStream(keyPath); | ||
| keyBytes = stream.readNBytes(1024 * 1024); | ||
| stream.close(); | ||
| } | ||
|
|
||
| InputStream stream = null; | ||
| if (isJson(keyBytes)) { | ||
| stream = new ByteArrayInputStream(keyBytes); | ||
| } else if (pvtKey != null) { | ||
| key = privateKeyFromPkcs8(pvtKey); | ||
| } else { | ||
| key = privateKeyFromP12Bytes(keyBytes, p12Password); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| } | ||
|
logachev marked this conversation as resolved.
|
||
|
|
||
| if (stream != null) { | ||
|
|
@@ -703,9 +708,9 @@ private static GoogleCredentials getServiceAccountImpersonatedCredentials( | |
| impersonationLifetimeInt); | ||
| } | ||
|
|
||
| static PrivateKey privateKeyFromP12File(String privateKeyFile, String password) { | ||
| static PrivateKey privateKeyFromP12Bytes(byte[] privateKey, String password) { | ||
| try { | ||
| InputStream stream = Files.newInputStream(Paths.get(privateKeyFile)); | ||
| InputStream stream = new ByteArrayInputStream(privateKey); | ||
| return SecurityUtils.loadPrivateKeyFromKeyStore( | ||
| SecurityUtils.getPkcs12KeyStore(), stream, "notasecret", "privatekey", password); | ||
| } catch (IOException | GeneralSecurityException e) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A resource leak vulnerability exists in the
getGoogleServiceAccountCredentialsmethod. TheFileInputStreamis not properly closed in afinallyblock or with a try-with-resources statement, which can lead to file descriptor exhaustion if an exception occurs duringstream.readNBytes(). It's recommended to use a try-with-resources statement to ensure the stream is always closed correctly.