1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 17:56:01 +02:00

Fix for PR 50810

PE/Coff guard agains bad values of String Table.

Model: cache the IBinaryArchive class in Archive.
This commit is contained in:
Alain Magloire 2004-02-05 17:33:15 +00:00
parent 9e531f825a
commit dfbc2241b6
6 changed files with 28 additions and 43 deletions

View file

@ -1,3 +1,16 @@
2004-02-05 Alain Magloire
PR 50810
Coff format the String Table section may have incorrect value.
We should guard against it.
* utils/org/eclipse/cdt/utils/Coff.java
* utils/org/eclipse/cdt/utils/PE.java
Cache the IBinaryArchive class so not to reload again.
* model/org/eclipse/cdt/internal/core/model/Archive.java
* model/org/eclipse/cdt/internal/core/model/CModelManager.java
2004-02-03 Alain Magloire 2004-02-03 Alain Magloire
PR 51143 PR 51143

View file

@ -5,31 +5,30 @@ package org.eclipse.cdt.internal.core.model;
* All Rights Reserved. * All Rights Reserved.
*/ */
import java.io.IOException;
import java.util.Map; import java.util.Map;
import org.eclipse.cdt.core.IBinaryParser;
import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive; import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive;
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.IArchive; import org.eclipse.cdt.core.model.IArchive;
import org.eclipse.cdt.core.model.IBinary; import org.eclipse.cdt.core.model.IBinary;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
public class Archive extends Openable implements IArchive { public class Archive extends Openable implements IArchive {
public Archive(ICElement parent, IFile file) { IBinaryArchive binaryArchive;
this(parent, file.getLocation());
public Archive(ICElement parent, IFile file, IBinaryArchive ar) {
this(parent, file.getLocation(), ar);
} }
public Archive(ICElement parent, IPath path) { public Archive(ICElement parent, IPath path, IBinaryArchive ar) {
super (parent, path, ICElement.C_ARCHIVE); super (parent, path, ICElement.C_ARCHIVE);
binaryArchive = ar;
} }
public IBinary[] getBinaries() { public IBinary[] getBinaries() {
@ -64,7 +63,7 @@ public class Archive extends Openable implements IArchive {
public boolean computeChildren(OpenableInfo info, IResource res) { public boolean computeChildren(OpenableInfo info, IResource res) {
IBinaryArchive ar = getBinaryArchive(res); IBinaryArchive ar = getBinaryArchive();
if (ar != null) { if (ar != null) {
IBinaryObject[] objects = ar.getObjects(); IBinaryObject[] objects = ar.getObjects();
for (int i = 0; i < objects.length; i++) { for (int i = 0; i < objects.length; i++) {
@ -78,27 +77,8 @@ public class Archive extends Openable implements IArchive {
return true; return true;
} }
IBinaryArchive getBinaryArchive(IResource res) { IBinaryArchive getBinaryArchive() {
IBinaryArchive archive = null; return binaryArchive;
IProject project = null;
IBinaryParser parser = null;
if (res != null) {
project = res.getProject();
}
if (project != null) {
parser = CModelManager.getDefault().getBinaryParser(project);
}
if (parser != null) {
try {
IPath path = res.getLocation();
IBinaryFile bfile = parser.getBinary(path);
if (bfile instanceof IBinaryArchive) {
archive = (IBinaryArchive) bfile;
}
} catch (IOException e) {
}
}
return archive;
} }
} }

View file

@ -17,8 +17,8 @@ import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CProjectNature; import org.eclipse.cdt.core.CProjectNature;
import org.eclipse.cdt.core.IBinaryParser; import org.eclipse.cdt.core.IBinaryParser;
import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive;
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
import org.eclipse.cdt.core.model.*;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ElementChangedEvent; import org.eclipse.cdt.core.model.ElementChangedEvent;
import org.eclipse.cdt.core.model.IArchive; import org.eclipse.cdt.core.model.IArchive;
@ -30,6 +30,7 @@ import org.eclipse.cdt.core.model.ICModel;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IElementChangedListener; import org.eclipse.cdt.core.model.IElementChangedListener;
import org.eclipse.cdt.core.model.IParent; import org.eclipse.cdt.core.model.IParent;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager; import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IFolder;
@ -230,7 +231,7 @@ public class CModelManager implements IResourceChangeListener {
} }
if (bin != null) { if (bin != null) {
if (bin.getType() == IBinaryFile.ARCHIVE) { if (bin.getType() == IBinaryFile.ARCHIVE) {
cfile = new Archive(parent, file); cfile = new Archive(parent, file, (IBinaryArchive)bin);
} else { } else {
cfile = new Binary(parent, file, bin); cfile = new Binary(parent, file, bin);
} }

View file

@ -19,13 +19,11 @@ import org.eclipse.core.runtime.IPath;
public class LibraryReferenceArchive extends Archive implements ILibraryReference { public class LibraryReferenceArchive extends Archive implements ILibraryReference {
ILibraryEntry entry; ILibraryEntry entry;
IBinaryArchive archive;
public LibraryReferenceArchive(ICElement parent, ILibraryEntry e, IBinaryArchive ar) { public LibraryReferenceArchive(ICElement parent, ILibraryEntry e, IBinaryArchive ar) {
super(parent, e.getLibraryPath()); super(parent, e.getLibraryPath(), ar);
setElementType(ICElement.C_VCONTAINER); setElementType(ICElement.C_VCONTAINER);
entry = e; entry = e;
archive = ar;
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -43,11 +41,4 @@ public class LibraryReferenceArchive extends Archive implements ILibraryReferenc
return entry.getLibraryPath(); return entry.getLibraryPath();
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.model.Archive#getBinaryArchive(org.eclipse.core.resources.IResource)
*/
IBinaryArchive getBinaryArchive(IResource res) {
return archive;
}
} }

View file

@ -478,7 +478,7 @@ public class Coff {
byte[] bytes = new byte[4]; byte[] bytes = new byte[4];
rfile.readFully(bytes); rfile.readFully(bytes);
int str_len = ReadMemoryAccess.getIntLE(bytes); int str_len = ReadMemoryAccess.getIntLE(bytes);
if (str_len > 4) { if (str_len > 4 && str_len < rfile.length()) {
str_len -= 4; str_len -= 4;
string_table = new byte[str_len]; string_table = new byte[str_len];
rfile.seek(offset + 4); rfile.seek(offset + 4);

View file

@ -550,7 +550,7 @@ public class PE {
byte[] bytes = new byte[4]; byte[] bytes = new byte[4];
accessFile.readFully(bytes); accessFile.readFully(bytes);
int str_len = ReadMemoryAccess.getIntLE(bytes); int str_len = ReadMemoryAccess.getIntLE(bytes);
if (str_len > 4) { if (str_len > 4 && str_len < accessFile.length()) {
str_len -= 4; str_len -= 4;
stringTable = new byte[str_len]; stringTable = new byte[str_len];
accessFile.seek(offset + 4); accessFile.seek(offset + 4);