Skip to content

Commit 9edca9a

Browse files
committed
GT-3261: Fixing possible IllegalArgumentException in sort comparator.
Integer subtraction could result in overflow.
1 parent f3e4cd0 commit 9edca9a

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/commands/SymbolTableCommand.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,11 @@ private void initSymbolTableCommand(FactoryBundledWithBinaryReader reader, MachH
8484
nlistList.add(NList.createNList(reader, is32bit));
8585
}
8686
// sort the entries by the index in the string table, so don't jump around reading
87-
List<NList> sortedList = nlistList.stream().sorted(
88-
(o1, o2) -> o1.getStringTableIndex() - o2.getStringTableIndex()).collect(
89-
Collectors.toList());
87+
List<NList> sortedList = nlistList
88+
.stream()
89+
.sorted((o1, o2) -> Integer.valueOf(o1.getStringTableIndex())
90+
.compareTo(Integer.valueOf(o2.getStringTableIndex())))
91+
.collect(Collectors.toList());
9092

9193
// initialize the NList strings from string table
9294
long stringTableOffset = stroff;

Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/dyld/DyldCacheLocalSymbolsInfo.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,11 @@ private void parseNList(MessageLog log, TaskMonitor monitor) throws CancelledExc
159159
monitor.incrementProgress(1);
160160
}
161161
// sort the entries by the index in the string table, so don't jump around reading
162-
List<NList> sortedList = nlistList.stream().sorted(
163-
(o1, o2) -> o1.getStringTableIndex() - o2.getStringTableIndex()).collect(
164-
Collectors.toList());
162+
List<NList> sortedList = nlistList
163+
.stream()
164+
.sorted((o1, o2) -> Integer.valueOf(o1.getStringTableIndex())
165+
.compareTo(Integer.valueOf(o2.getStringTableIndex())))
166+
.collect(Collectors.toList());
165167

166168
// initialize the NList strings from string table
167169
long stringTableOffset = startIndex + stringsOffset;

0 commit comments

Comments
 (0)