jt2594838 commented on code in PR #17624:
URL: https://github.com/apache/iotdb/pull/17624#discussion_r3216680432


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/statement/crud/LoadTsFileStatement.java:
##########
@@ -120,23 +140,63 @@ protected LoadTsFileStatement() {
     this.statementType = StatementType.MULTI_BATCH_INSERT;
   }
 
-  private static List<File> findAllTsFile(File file) {
+  private static List<File> findAllTsFile(File file, boolean 
validateSourcePath)
+      throws FileNotFoundException {
     final File[] files = file.listFiles();
     if (files == null) {
       return Collections.emptyList();
     }
 
     final List<File> tsFiles = new ArrayList<>();
     for (File nowFile : files) {
+      if (validateSourcePath) {
+        validateLoadSourcePath(nowFile);
+      }
       if (nowFile.getName().endsWith(TsFileConstant.TSFILE_SUFFIX)) {
         tsFiles.add(nowFile);
       } else if (nowFile.isDirectory()) {
-        tsFiles.addAll(findAllTsFile(nowFile));
+        tsFiles.addAll(findAllTsFile(nowFile, validateSourcePath));
       }
     }
     return tsFiles;
   }
 
+  public static void validateLoadSourcePath(final String filePath) throws 
FileNotFoundException {
+    validateLoadSourcePath(new File(filePath));
+  }
+
+  private static void validateLoadSourcePath(final File file) throws 
FileNotFoundException {
+    if 
(!IoTDBDescriptor.getInstance().getConfig().isLoadTsFileSourcePathCheckEnabled())
 {
+      return;
+    }
+
+    final Path sourcePath = canonicalPath(file);
+    final String[] allowedDirs =
+        IoTDBDescriptor.getInstance().getConfig().getLoadTsFileAllowedDirs();
+
+    for (final String allowedDir : allowedDirs) {
+      if (sourcePath.startsWith(canonicalPath(new File(allowedDir)))) {
+        return;
+      }
+    }

Review Comment:
   May pre-compute the canonicalPaths of allowedDirs in IoTDBConfig to avoid 
redundant calculation.



-- 
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]

Reply via email to