github-code-scanning[bot] commented on code in PR #13298:
URL:
https://github.com/apache/dolphinscheduler/pull/13298#discussion_r1058700526
##########
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java:
##########
@@ -264,4 +267,41 @@
}
}
+ /**
+ * Calculate file checksum with CRC32 algorithm
+ * @param pathName
+ * @return checksum of file/dir
+ */
+ public static String getFileChecksum(String pathName) throws IOException {
+ CRC32 crc32 = new CRC32();
+ File file = new File(pathName);
+ String crcString = "";
+ if (file.isDirectory()) {
+ // file system interface remains the same order
+ String[] subPaths = file.list();
+ StringBuilder concatenatedCRC = new StringBuilder();
+ for (String subPath : subPaths) {
+ concatenatedCRC.append(getFileChecksum(pathName +
FOLDER_SEPARATOR + subPath));
+ }
+ crcString = concatenatedCRC.toString();
+ } else {
+ FileInputStream fileInputStream = null;
+ CheckedInputStream checkedInputStream = null;
+ try {
+ fileInputStream = new FileInputStream(pathName);
+ checkedInputStream = new CheckedInputStream(fileInputStream,
crc32);
+ while (checkedInputStream.read() != -1) {
+ }
+ } catch (IOException e) {
+ throw new IOException("Calculate checksum error.");
+ } finally {
+ fileInputStream.close();
Review Comment:
## Dereferenced variable may be null
Variable [fileInputStream](1) may be null at this access because of
[this](2) assignment.
[Show more
details](https://github.com/apache/dolphinscheduler/security/code-scanning/2457)
##########
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java:
##########
@@ -264,4 +267,41 @@
}
}
+ /**
+ * Calculate file checksum with CRC32 algorithm
+ * @param pathName
+ * @return checksum of file/dir
+ */
+ public static String getFileChecksum(String pathName) throws IOException {
+ CRC32 crc32 = new CRC32();
+ File file = new File(pathName);
+ String crcString = "";
+ if (file.isDirectory()) {
+ // file system interface remains the same order
+ String[] subPaths = file.list();
+ StringBuilder concatenatedCRC = new StringBuilder();
+ for (String subPath : subPaths) {
+ concatenatedCRC.append(getFileChecksum(pathName +
FOLDER_SEPARATOR + subPath));
+ }
+ crcString = concatenatedCRC.toString();
+ } else {
+ FileInputStream fileInputStream = null;
+ CheckedInputStream checkedInputStream = null;
+ try {
+ fileInputStream = new FileInputStream(pathName);
+ checkedInputStream = new CheckedInputStream(fileInputStream,
crc32);
+ while (checkedInputStream.read() != -1) {
+ }
+ } catch (IOException e) {
+ throw new IOException("Calculate checksum error.");
+ } finally {
+ fileInputStream.close();
+ checkedInputStream.close();
Review Comment:
## Dereferenced variable may be null
Variable [checkedInputStream](1) may be null at this access because of
[this](2) assignment.
[Show more
details](https://github.com/apache/dolphinscheduler/security/code-scanning/2458)
--
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]