Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-6903 Corrected 12.1.1 Ghidra Server regression error and cleanup invalid folder item.

ghidra15494795a7cab
diff --git a/Ghidra/Features/GhidraServer/src/main/java/ghidra/server/stream/RemoteInputBlockStreamHandle.java b/Ghidra/Features/GhidraServer/src/main/java/ghidra/server/stream/RemoteInputBlockStreamHandle.java
index bee6a3ebe8..e18501ef83 100644
--- a/Ghidra/Features/GhidraServer/src/main/java/ghidra/server/stream/RemoteInputBlockStreamHandle.java
+++ b/Ghidra/Features/GhidraServer/src/main/java/ghidra/server/stream/RemoteInputBlockStreamHandle.java
@@ -141,8 +141,14 @@ public class RemoteInputBlockStreamHandle extends RemoteBlockStreamHandle<InputB
try (OutputStream out = getBlockInputStream(socket)) {
copyBlockData(inputBlockStream, out);
+
+ // Done with compressed stream, force compressed data to flush
+ // before final handshake occurs
+ if (out instanceof RemoteDeflaterOutputStream deflatorOut) {
+ deflatorOut.finish();
+ }
- // perform final handshake before close (uncompressed)
+ // Perform final handshake before close (uncompressed)
writeStreamEnd(socket);
readStreamEnd(socket, false);
}
diff --git a/Ghidra/Framework/FileSystem/src/main/java/ghidra/framework/store/local/LocalFolderItem.java b/Ghidra/Framework/FileSystem/src/main/java/ghidra/framework/store/local/LocalFolderItem.java
index c8e539e5fd..2a3f4195e2 100644
--- a/Ghidra/Framework/FileSystem/src/main/java/ghidra/framework/store/local/LocalFolderItem.java
+++ b/Ghidra/Framework/FileSystem/src/main/java/ghidra/framework/store/local/LocalFolderItem.java
@@ -367,7 +367,7 @@ public abstract class LocalFolderItem implements FolderItem {
File dataDir = getDataDir();
File chkDir = new File(dataDir.getParentFile(), dataDir.getName() + ".delete");
FileUtilities.deleteDir(chkDir);
- if (useDataDir && dataDir.exists() && !dataDir.renameTo(chkDir)) {
+ if (dataDir.exists() && !dataDir.renameTo(chkDir)) {
throw new FileInUseException(getName() + " is in use");
}
boolean success = false;
@@ -380,15 +380,13 @@ public abstract class LocalFolderItem implements FolderItem {
}
finally {
if (!success) {
- if (useDataDir && !dataDir.exists() && chkDir.exists() &&
+ if (!dataDir.exists() && chkDir.exists() &&
propertyFile.exists()) {
chkDir.renameTo(dataDir);
}
}
else {
- if (useDataDir) {
- FileUtilities.deleteDir(chkDir);
- }
+ FileUtilities.deleteDir(chkDir);
log("file deleted", user);
}
}
@@ -785,13 +783,16 @@ public abstract class LocalFolderItem implements FolderItem {
* Returns the appropriate instantiation of a LocalFolderItem
* based upon a specified property file which resides within a
* LocalFileSystem.
+ * <p>
+ * {@link LocalUnknownFolderItem} will be returned for unknown/unsupported content.
+ *
* @param fileSystem local file system which contains property file
* @param propertyFile property file which identifies the folder item.
- * @return folder item
+ * @return folder item or null if invalid item.
*/
static LocalFolderItem getFolderItem(LocalFileSystem fileSystem,
ItemPropertyFile propertyFile) {
- int fileType = propertyFile.getInt(FILE_TYPE, UNKNOWN_FILE_TYPE);
+ int fileType = propertyFile.getInt(FILE_TYPE, Integer.MIN_VALUE);
try {
if (fileType == DATAFILE_FILE_TYPE) {
return new LocalDataFileItem(fileSystem, propertyFile);
@@ -802,9 +803,15 @@ public abstract class LocalFolderItem implements FolderItem {
else if (fileType == LINK_FILE_TYPE) {
return new LocalTextDataItem(fileSystem, propertyFile);
}
- else if (fileType == UNKNOWN_FILE_TYPE) {
- log.error("Folder item has unspecified file type: " + new File(
+ else if (fileType == Integer.MIN_VALUE) {
+ // Item not properly created and in bad state
+ // Use badItem instance to remove all related storage
+ LocalUnknownFolderItem badItem =
+ new LocalUnknownFolderItem(fileSystem, propertyFile);
+ badItem.delete(LATEST_VERSION, "REPAIR");
+ log.error("Removing folder item with unspecified file type: " + new File(
propertyFile.getParentStorageDirectory(), propertyFile.getStorageName()));
+ return null; // triggers storage deallocation
}
else {
log.error("Folder item has unsupported file type (" + fileType + "): " + new File(
diff --git a/Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/server/remote/ServerTestUtil.java b/Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/server/remote/ServerTestUtil.java
index 4f723f7d6c..207a3973fb 100644
--- a/Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/server/remote/ServerTestUtil.java
+++ b/Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/server/remote/ServerTestUtil.java
@@ -29,6 +29,7 @@ import javax.rmi.ssl.SslRMIClientSocketFactory;
import org.apache.commons.lang3.RandomStringUtils;
+import db.buffers.DataBuffer;
import generic.hash.HashUtilities;
import generic.test.*;
import ghidra.framework.Application;
@@ -92,6 +93,8 @@ public class ServerTestUtil {
private static final int SERVER_STARTUP_MAXWAIT_MS = 20000;
+ public static boolean enableCompressionOnServerStart = true;
+
private static IOThread cmdOut;
private static IOThread cmdErr;
private static Process serverProcess;
@@ -413,6 +416,9 @@ public class ServerTestUtil {
boolean enableAltLoginName, boolean enableSSHAuthentication,
boolean enableAnonymousAuthentication) throws IOException {
+ // Set client-side compression to match server
+ DataBuffer.enableCompressedSerializationOutput(enableCompressionOnServerStart);
+
if (port == 0) {
port = GHIDRA_TEST_SERVER_PORT;
}
@@ -442,6 +448,7 @@ public class ServerTestUtil {
argList.add("-Xdebug");
argList.add("-Xnoagent");
argList.add("-Djava.compiler=NONE");
+ argList.add("-Ddb.buffers.DataBuffer.compressedOutput=" + enableCompressionOnServerStart);
argList.add("-D" + DefaultTrustManagerFactory.GHIDRA_CACERTS_PATH_PROPERTY + "=" +
getTestPkiCACertsPath());
argList.add("-D" + DefaultKeyManagerFactory.KEYSTORE_PATH_PROPERTY + "=" +