Merge remote-tracking branch 'origin/GP-5999_dev747368_fix_coff_NPE'

This commit is contained in:
Ryan Kurtz 2025-09-18 13:10:53 -04:00
commit 1ae4378cfd

View file

@ -16,8 +16,7 @@
package ghidra.app.util.bin.format.coff.archive; package ghidra.app.util.bin.format.coff.archive;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import ghidra.app.util.bin.*; import ghidra.app.util.bin.*;
import ghidra.app.util.bin.format.coff.CoffException; import ghidra.app.util.bin.format.coff.CoffException;
@ -42,13 +41,14 @@ public final class CoffArchiveHeader implements StructConverter {
* Returns true if the data contained in the {@link ByteProvider provider} contains * Returns true if the data contained in the {@link ByteProvider provider} contains
* a COFF Archive file. * a COFF Archive file.
* *
* @param provider * @param provider {@link ByteProvider} stream
* @return * @return boolean true if stream contains a CoffArchiveHeader at position 0
* @throws IOException * @throws IOException if error reading
*/ */
public static boolean isMatch(ByteProvider provider) throws IOException { public static boolean isMatch(ByteProvider provider) throws IOException {
return (provider.length() > CoffArchiveConstants.MAGIC_LEN) && CoffArchiveConstants.MAGIC return (provider.length() >= CoffArchiveConstants.MAGIC_LEN) &&
.equals(new String(provider.readBytes(0, CoffArchiveConstants.MAGIC_LEN))); Arrays.equals(CoffArchiveConstants.MAGIC_BYTES,
provider.readBytes(0, CoffArchiveConstants.MAGIC_LEN));
} }
/** /**
@ -75,9 +75,7 @@ public final class CoffArchiveHeader implements StructConverter {
CoffArchiveHeader cah = new CoffArchiveHeader(); CoffArchiveHeader cah = new CoffArchiveHeader();
long eofPos = reader.length() - CoffArchiveMemberHeader.CAMH_MIN_SIZE; while (reader.hasNext(CoffArchiveMemberHeader.CAMH_MIN_SIZE)) {
while (reader.getPointerIndex() < eofPos) {
if (monitor.isCancelled()) { if (monitor.isCancelled()) {
break; break;
} }