NationalSecurityAgency / ghidra

Ghidra is a software reverse engineering (SRE) framework
https://www.nsa.gov/ghidra
Apache License 2.0
51.48k stars 5.86k forks source link

StackOverflow running RecoverClassesFromRTTIScript #6832

Closed epinter closed 1 month ago

epinter commented 2 months ago

Describe the bug The script RecoverClassesFromRTTIScript.java terminates with StackOverflowError.

To Reproduce Steps to reproduce the behavior:

  1. Run the script RecoverClassesFromRTTIScript.java
  2. Wait until the script starts to run processInlinedConstructorsAndDestructors, the exception occurs if a function A calls B and B calls A.

Expected behavior The script must finish without exceptions.

Attachments If applicable, please attach any files that caused problems or log files generated by the software.

Environment (please complete the following information):

Additional context

java.lang.reflect.InvocationTargetException
    at ghidra.app.plugin.core.analysis.AutoAnalysisManager$AnalysisWorkerCommand.applyTo(AutoAnalysisManager.java:1705)
    at ghidra.app.plugin.core.analysis.AutoAnalysisManager$AnalysisWorkerCommand.applyTo(AutoAnalysisManager.java:1586)
    at ghidra.app.plugin.core.analysis.AutoAnalysisManager$AnalysisTaskWrapper.run(AutoAnalysisManager.java:660)
    at ghidra.app.plugin.core.analysis.AutoAnalysisManager.startAnalysis(AutoAnalysisManager.java:760)
    at ghidra.app.plugin.core.analysis.AutoAnalysisManager.startAnalysis(AutoAnalysisManager.java:639)
    at ghidra.app.plugin.core.analysis.AutoAnalysisManager.startAnalysis(AutoAnalysisManager.java:604)
    at ghidra.app.plugin.core.analysis.AnalysisBackgroundCommand.applyTo(AnalysisBackgroundCommand.java:55)
    at ghidra.app.plugin.core.analysis.AnalysisBackgroundCommand.applyTo(AnalysisBackgroundCommand.java:33)
    at ghidra.framework.plugintool.mgr.BackgroundCommandTask.run(BackgroundCommandTask.java:103)
    at ghidra.framework.plugintool.mgr.ToolTaskManager.run(ToolTaskManager.java:351)
    at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: java.lang.StackOverflowError
    at java.base/java.util.HashMap.putVal(HashMap.java:635)
    at java.base/java.util.HashMap.put(HashMap.java:618)
    at db.NodeMgr.addNode(NodeMgr.java:209)
    at db.FixedKeyNode.<init>(FixedKeyNode.java:61)
    at db.FixedKeyInteriorNode.<init>(FixedKeyInteriorNode.java:52)
    at db.NodeMgr.getFixedKeyNode(NodeMgr.java:304)
    at db.Table.getFieldKeyNode(Table.java:166)
    at db.Table$ShortDurationFieldKeyIterator.initialize(Table.java:3852)
    at db.Table$ShortDurationFieldKeyIterator.<init>(Table.java:3826)
    at db.Table$FieldKeyIterator.<init>(Table.java:3370)
    at db.Table.fieldKeyIterator(Table.java:2005)
    at db.FieldIndexTable$PrimaryKeyIterator.<init>(FieldIndexTable.java:493)
    at db.FieldIndexTable.keyIterator(FieldIndexTable.java:410)
    at db.Table.indexIterator(Table.java:1569)
    at ghidra.program.database.util.AddressRangeMapDB.getAddressSet(AddressRangeMapDB.java:360)
    at ghidra.program.database.symbol.NamespaceManager.getAddressSet(NamespaceManager.java:305)
    at ghidra.program.database.symbol.NamespaceManager.getAddressSet(NamespaceManager.java:283)
    at ghidra.program.database.function.FunctionDB.getBody(FunctionDB.java:353)
    at classrecovery.RecoveredClassHelper.getFunctionCallMap(RecoveredClassHelper.java:415)
    at classrecovery.RecoveredClassHelper.getFunctionCallMap(RecoveredClassHelper.java:439)
    at classrecovery.RecoveredClassHelper.getFunctionCallMap(RecoveredClassHelper.java:439)
    at classrecovery.RecoveredClassHelper.getFunctionCallMap(RecoveredClassHelper.java:439)
    at classrecovery.RecoveredClassHelper.getFunctionCallMap(RecoveredClassHelper.java:439)
    at classrecovery.RecoveredClassHelper.getFunctionCallMap(RecoveredClassHelper.java:439)
    at classrecovery.RecoveredClassHelper.getFunctionCallMap(RecoveredClassHelper.java:439)
    at classrecovery.RecoveredClassHelper.getFunctionCallMap(RecoveredClassHelper.java:439)
    at classrecovery.RecoveredClassHelper.getFunctionCallMap(RecoveredClassHelper.java:439)
    at classrecovery.RecoveredClassHelper.getFunctionCallMap(RecoveredClassHelper.java:439)
epinter commented 2 months ago

The bug seems to be introduced by https://github.com/NationalSecurityAgency/ghidra/commit/f657b11c1d64d5e66ca3ca71886af321de2e81f8