Skip to content

Commit

Permalink
Fix potentially unsafe VFS recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
jshiell committed Aug 6, 2022
1 parent b9dc37e commit f0ac43c
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/main/java/org/infernus/idea/checkstyle/actions/BaseAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileVisitor;
import com.intellij.openapi.wm.ToolWindow;
import org.infernus.idea.checkstyle.CheckStyleBundle;
import org.infernus.idea.checkstyle.StaticScanner;
Expand All @@ -17,6 +19,7 @@
import org.jetbrains.annotations.Nullable;

import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;

import static java.util.Optional.ofNullable;
import static org.infernus.idea.checkstyle.actions.ToolWindowAccess.actOnToolWindowPanel;
Expand Down Expand Up @@ -79,14 +82,23 @@ protected StaticScanner staticScanner(final Project project) {
}

protected boolean containsAtLeastOneFile(@NotNull final VirtualFile... files) {
boolean result = false;
final var result = new AtomicBoolean(false);
for (VirtualFile file : files) {
if ((file.isDirectory() && containsAtLeastOneFile(file.getChildren())) || (!file.isDirectory() && file
.isValid())) {
result = true;
VfsUtilCore.visitChildrenRecursively(file, new VirtualFileVisitor<>() {
@Override
public @NotNull Result visitFileEx(@NotNull final VirtualFile file) {
if (!file.isDirectory() && file.isValid()) {
result.set(true);
return SKIP_CHILDREN;
}
return CONTINUE;
}
});

if (result.get()) {
break;
}
}
return result;
return result.get();
}
}

0 comments on commit f0ac43c

Please sign in to comment.