GT-3261: Fixing possible IllegalArgumentException in sort comparator.

Integer subtraction could result in overflow.
This commit is contained in:
Ryan Kurtz 2019-11-15 08:50:46 -05:00
parent f3e4cd0a00
commit 9edca9afec
2 changed files with 10 additions and 6 deletions

View File

@ -84,9 +84,11 @@ public class SymbolTableCommand extends LoadCommand {
nlistList.add(NList.createNList(reader, is32bit));
}
// sort the entries by the index in the string table, so don't jump around reading
List<NList> sortedList = nlistList.stream().sorted(
(o1, o2) -> o1.getStringTableIndex() - o2.getStringTableIndex()).collect(
Collectors.toList());
List<NList> sortedList = nlistList
.stream()
.sorted((o1, o2) -> Integer.valueOf(o1.getStringTableIndex())
.compareTo(Integer.valueOf(o2.getStringTableIndex())))
.collect(Collectors.toList());
// initialize the NList strings from string table
long stringTableOffset = stroff;

View File

@ -159,9 +159,11 @@ public class DyldCacheLocalSymbolsInfo implements StructConverter {
monitor.incrementProgress(1);
}
// sort the entries by the index in the string table, so don't jump around reading
List<NList> sortedList = nlistList.stream().sorted(
(o1, o2) -> o1.getStringTableIndex() - o2.getStringTableIndex()).collect(
Collectors.toList());
List<NList> sortedList = nlistList
.stream()
.sorted((o1, o2) -> Integer.valueOf(o1.getStringTableIndex())
.compareTo(Integer.valueOf(o2.getStringTableIndex())))
.collect(Collectors.toList());
// initialize the NList strings from string table
long stringTableOffset = startIndex + stringsOffset;