diff options
author | Alain Magloire | 2004-02-05 17:40:58 +0000 |
---|---|---|
committer | Alain Magloire | 2004-02-05 17:40:58 +0000 |
commit | af52cdf27d54d42652737f19e60fd7d54e570e09 (patch) | |
tree | a934f01fbccffdb1afaaa677e9bb65de97b57b8f | |
parent | 422c72bec0a99623370eb87ae3740be63ff4caa2 (diff) | |
download | org.eclipse.cdt-af52cdf27d54d42652737f19e60fd7d54e570e09.tar.gz org.eclipse.cdt-af52cdf27d54d42652737f19e60fd7d54e570e09.tar.xz org.eclipse.cdt-af52cdf27d54d42652737f19e60fd7d54e570e09.zip |
Fix PR 50810
COFF/PE parser the String Table had wrong value.
Guard against it.
Model:
Cache the IBinaryArchive class in Archive.
5 files changed, 26 insertions, 32 deletions
diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog index f6db24f0319..d01b19ec913 100644 --- a/core/org.eclipse.cdt.core/ChangeLog +++ b/core/org.eclipse.cdt.core/ChangeLog @@ -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 diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Archive.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Archive.java index 9a745ae998b..28f4a9bb107 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Archive.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Archive.java @@ -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 bin) { + this(parent, file.getLocation(), bin); } - public Archive(ICElement parent, IPath path) { + public Archive(ICElement parent, IPath path, IBinaryArchive bin) { super (parent, path, ICElement.C_ARCHIVE); + binaryArchive = bin; } 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; } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java index 080f830872b..3c60eb54bfb 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java @@ -18,6 +18,7 @@ import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CProjectNature; import org.eclipse.cdt.core.IBinaryParser; import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; +import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ElementChangedEvent; import org.eclipse.cdt.core.model.IArchive; @@ -229,7 +230,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); } diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/Coff.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/Coff.java index 63d47972a16..3c9e74bdd10 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/Coff.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/Coff.java @@ -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); diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/PE.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/PE.java index d95e27ab4f0..f65736b4775 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/PE.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/coff/PE.java @@ -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); |