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;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
import ghidra.app.util.bin.*;
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
* a COFF Archive file.
*
* @param provider
* @return
* @throws IOException
* @param provider {@link ByteProvider} stream
* @return boolean true if stream contains a CoffArchiveHeader at position 0
* @throws IOException if error reading
*/
public static boolean isMatch(ByteProvider provider) throws IOException {
return (provider.length() > CoffArchiveConstants.MAGIC_LEN) && CoffArchiveConstants.MAGIC
.equals(new String(provider.readBytes(0, CoffArchiveConstants.MAGIC_LEN)));
return (provider.length() >= 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();
long eofPos = reader.length() - CoffArchiveMemberHeader.CAMH_MIN_SIZE;
while (reader.getPointerIndex() < eofPos) {
while (reader.hasNext(CoffArchiveMemberHeader.CAMH_MIN_SIZE)) {
if (monitor.isCancelled()) {
break;
}