IJ-CR-108265 [java-decompiler] IDEA-198397 add cancelled checks for java-decompiler. Add some limits

GitOrigin-RevId: c2ebda314570d885d50cd6c523e990d238ac4491
This commit is contained in:
Mikhail Pyltsin
2023-06-18 16:12:35 +02:00
committed by intellij-monorepo-bot
parent 3c2f371c32
commit b26d7c9740
3 changed files with 44 additions and 11 deletions

View File

@@ -27,6 +27,7 @@ import com.intellij.psi.compiled.ClassFileDecompilers
import com.intellij.psi.impl.compiled.ClsFileImpl
import com.intellij.ui.components.LegalNoticeDialog
import com.intellij.util.FileContentUtilCore
import com.intellij.util.ui.EDT
import org.jetbrains.java.decompiler.main.CancellationManager
import org.jetbrains.java.decompiler.main.decompiler.BaseDecompiler
import org.jetbrains.java.decompiler.main.extern.ClassFormatException
@@ -61,6 +62,8 @@ class IdeaDecompiler : ClassFileDecompilers.Light() {
IFernflowerPreferences.NEW_LINE_SEPARATOR to "1",
IFernflowerPreferences.BANNER to BANNER,
IFernflowerPreferences.MAX_PROCESSING_METHOD to 60,
IFernflowerPreferences.MAX_BYTES_CLASS_NOT_UNDER_PROGRESS to 20_000, //approximately 2_000 lines
IFernflowerPreferences.MAX_BYTES_CLASS to 80_000, //approximately 8_000 lines
IFernflowerPreferences.INDENT_STRING to indent,
IFernflowerPreferences.IGNORE_INVALID_BYTECODE to "1",
IFernflowerPreferences.VERIFY_ANONYMOUS_CLASSES to "1",
@@ -122,9 +125,30 @@ class IdeaDecompiler : ClassFileDecompilers.Light() {
override fun accepts(file: VirtualFile): Boolean = true
override fun getText(file: VirtualFile): CharSequence =
if (canWork()) TASK_KEY.pop(file)?.get() ?: decompile(file)
else ClsFileImpl.decompile(file)
override fun getText(file: VirtualFile): CharSequence {
if (canWork()) {
val previous = TASK_KEY.pop(file)?.get()
if (previous != null) {
return previous
}
else {
val maxBytesNotUnderProgress = myOptions.value[IFernflowerPreferences.MAX_BYTES_CLASS_NOT_UNDER_PROGRESS]?.toString()?.toIntOrNull() ?: 0
val maxBytes = myOptions.value[IFernflowerPreferences.MAX_BYTES_CLASS]?.toString()?.toIntOrNull() ?: 0
return if (!ApplicationManager.getApplication().isUnitTestMode &&
(maxBytesNotUnderProgress > 0 && EDT.isCurrentThreadEdt() && file.length > maxBytesNotUnderProgress) ||
(maxBytes > 0 && file.length > maxBytes)
) {
ClsFileImpl.decompile(file)
}
else {
decompile(file)
}
}
}
else {
return ClsFileImpl.decompile(file)
}
}
private fun decompile(file: VirtualFile): CharSequence {
val indicator = ProgressManager.getInstance().progressIndicator
@@ -202,19 +226,19 @@ class IdeaDecompiler : ClassFileDecompilers.Light() {
}
}
override fun saveFolder(path: String) { }
override fun saveFolder(path: String) {}
override fun copyFile(source: String, path: String, entryName: String) { }
override fun copyFile(source: String, path: String, entryName: String) {}
override fun createArchive(path: String, archiveName: String, manifest: Manifest) { }
override fun createArchive(path: String, archiveName: String, manifest: Manifest) {}
override fun saveDirEntry(path: String, archiveName: String, entryName: String) { }
override fun saveDirEntry(path: String, archiveName: String, entryName: String) {}
override fun copyEntry(source: String, path: String, archiveName: String, entry: String) { }
override fun copyEntry(source: String, path: String, archiveName: String, entry: String) {}
override fun saveClassEntry(path: String, archiveName: String, qualifiedName: String, entryName: String, content: String) { }
override fun saveClassEntry(path: String, archiveName: String, qualifiedName: String, entryName: String, content: String) {}
override fun closeArchive(path: String, archiveName: String) { }
override fun closeArchive(path: String, archiveName: String) {}
}
private fun <T> Key<T>.pop(holder: UserDataHolder): T? {