1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 01:36: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
PR 51143

View file

@ -5,31 +5,30 @@ package org.eclipse.cdt.internal.core.model;
* All Rights Reserved.
*/
import java.io.IOException;
import java.util.Map;
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.IBinaryObject;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.IArchive;
import org.eclipse.cdt.core.model.IBinary;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
public class Archive extends Openable implements IArchive {
public Archive(ICElement parent, IFile file) {
this(parent, file.getLocation());
IBinaryArchive binaryArchive;
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);
binaryArchive = ar;
}
public IBinary[] getBinaries() {
@ -64,7 +63,7 @@ public class Archive extends Openable implements IArchive {
public boolean computeChildren(OpenableInfo info, IResource res) {
IBinaryArchive ar = getBinaryArchive(res);
IBinaryArchive ar = getBinaryArchive();
if (ar != null) {
IBinaryObject[] objects = ar.getObjects();
for (int i = 0; i < objects.length; i++) {
@ -78,27 +77,8 @@ public class Archive extends Openable implements IArchive {
return true;
}
IBinaryArchive getBinaryArchive(IResource res) {
IBinaryArchive archive = null;
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;
IBinaryArchive getBinaryArchive() {
return binaryArchive;
}
}

View file

@ -17,8 +17,8 @@ import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CProjectNature;
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.model.*;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ElementChangedEvent;
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.IElementChangedListener;
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.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
@ -230,7 +231,7 @@ public class CModelManager implements IResourceChangeListener {
}
if (bin != null) {
if (bin.getType() == IBinaryFile.ARCHIVE) {
cfile = new Archive(parent, file);
cfile = new Archive(parent, file, (IBinaryArchive)bin);
} else {
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 {
ILibraryEntry entry;
IBinaryArchive archive;
public LibraryReferenceArchive(ICElement parent, ILibraryEntry e, IBinaryArchive ar) {
super(parent, e.getLibraryPath());
super(parent, e.getLibraryPath(), ar);
setElementType(ICElement.C_VCONTAINER);
entry = e;
archive = ar;
}
/* (non-Javadoc)
@ -43,11 +41,4 @@ public class LibraryReferenceArchive extends Archive implements ILibraryReferenc
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];
rfile.readFully(bytes);
int str_len = ReadMemoryAccess.getIntLE(bytes);
if (str_len > 4) {
if (str_len > 4 && str_len < rfile.length()) {
str_len -= 4;
string_table = new byte[str_len];
rfile.seek(offset + 4);

View file

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