Ghidra is a software reverse engineering (SRE) framework
GT-3400 Fix divide by zero in Ext4FileSystem, charset also. #1342
dev747368e5a59b9def1e
diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ext4/Ext4FileSystem.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ext4/Ext4FileSystem.javaindex 538e9fa1d7..92c131e247 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ext4/Ext4FileSystem.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ext4/Ext4FileSystem.java@@ -16,6 +16,8 @@package ghidra.file.formats.ext4;import java.io.*;+import java.nio.charset.Charset;+import java.nio.charset.StandardCharsets;import java.util.List;import ghidra.app.util.bin.BinaryReader;@@ -29,6 +31,8 @@ import ghidra.util.task.TaskMonitor;@FileSystemInfo(type = "ext4", description = "EXT4", factory = Ext4FileSystemFactory.class)public class Ext4FileSystem implements GFileSystem {+ public static final Charset EXT4_DEFAULT_CHARSET = StandardCharsets.UTF_8;+private FileSystemIndexHelper<Ext4File> fsih;private FileSystemRefManager refManager = new FileSystemRefManager(this);private FSRLRoot fsrl;@@ -57,6 +61,9 @@ public class Ext4FileSystem implements GFileSystem {blockSize = (int) Math.pow(2, (10 + s_log_block_size));int groupSize = blockSize * superBlock.getS_blocks_per_group();+ if (groupSize <= 0) {+ throw new IOException("Invalid groupSize: " + groupSize);+ }int numGroups = (int) (provider.length() / groupSize);if (provider.length() % groupSize != 0) {numGroups++;diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ext4/Ext4SuperBlock.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ext4/Ext4SuperBlock.javaindex 44b2bf12bf..d2a7e4b7d6 100644--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ext4/Ext4SuperBlock.java+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/ext4/Ext4SuperBlock.java@@ -15,12 +15,12 @@*/package ghidra.file.formats.ext4;+import java.io.IOException;+import ghidra.app.util.bin.*;import ghidra.program.model.data.*;import ghidra.util.exception.DuplicateNameException;-import java.io.IOException;-public class Ext4SuperBlock implements StructConverter {private int s_inodes_count;@@ -355,7 +355,7 @@ public class Ext4SuperBlock implements StructConverter {while (i < s_volume_name.length && s_volume_name[i] != '\0') {i++;}- return new String(s_volume_name, 0, i);+ return new String(s_volume_name, 0, i, Ext4FileSystem.EXT4_DEFAULT_CHARSET);}public byte[] getS_last_mounted() {