From 00df1402281abae45637be3c261744d63076801e Mon Sep 17 00:00:00 2001 From: Marc-Andre Laperle Date: Mon, 18 Jun 2018 11:13:23 -0400 Subject: [PATCH] Bug 535911: Better error in the presence of compressed ELF section This doesn't implement reading compressed ELF section, but at least it gives a more useful error instead of a simple "IllegalArgumentException" with no clue. Change-Id: Ib0ee1ab9e3aed7aeba184f13262b59ef21afcd32 Signed-off-by: Marc-Andre Laperle --- .../.settings/.api_filters | 8 ++++++++ core/org.eclipse.cdt.core/META-INF/MANIFEST.MF | 2 +- .../utils/org/eclipse/cdt/utils/elf/Elf.java | 18 +++++++++++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/core/org.eclipse.cdt.core/.settings/.api_filters b/core/org.eclipse.cdt.core/.settings/.api_filters index 98ebe057151..e054e9ba124 100644 --- a/core/org.eclipse.cdt.core/.settings/.api_filters +++ b/core/org.eclipse.cdt.core/.settings/.api_filters @@ -68,4 +68,12 @@ + + + + + + + + diff --git a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF index b018bbf4f97..39629cd9221 100644 --- a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF +++ b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.cdt.core; singleton:=true -Bundle-Version: 6.5.0.qualifier +Bundle-Version: 6.6.0.qualifier Bundle-Activator: org.eclipse.cdt.core.CCorePlugin Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/Elf.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/Elf.java index 812b22ec933..a516c1d9f3e 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/Elf.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/Elf.java @@ -302,6 +302,10 @@ public class Elf { public final static int SHF_WRITE = 1; public final static int SHF_ALLOC = 2; public final static int SHF_EXECINTR = 4; + /** + * @since 6.6 + */ + public final static int SHF_COMPRESSED = 2048; /* note_types */ /** @@ -324,17 +328,26 @@ public class Elf { * @since 5.1 */ public ByteBuffer mapSectionData() throws IOException { + makeSureNotCompressed(); sections_mapped = true; return efile.getChannel().map(MapMode.READ_ONLY, sh_offset, sh_size).load().asReadOnlyBuffer(); } public byte[] loadSectionData() throws IOException { + makeSureNotCompressed(); byte[] data = new byte[(int)sh_size]; efile.seek(sh_offset); efile.read(data); return data; } + private void makeSureNotCompressed() throws IOException { + if ((sh_flags & SHF_COMPRESSED) != 0) { + // No point in continuing, any seek() or map() will be wrong. + throw new IOException("Compressed sections are unsupported (SHF_COMPRESSED): " + toString()); //$NON-NLS-1$ + } + } + @Override public String toString() { try { @@ -342,6 +355,7 @@ public class Elf { final int shstrndx= ehdr.e_shstrndx & 0xffff; // unsigned short if (shstrndx > sections.length || shstrndx < 0) return EMPTY_STRING; + sections[shstrndx].makeSureNotCompressed(); int size = (int)sections[shstrndx].sh_size; if (size <= 0 || size > efile.length()) return EMPTY_STRING; @@ -367,10 +381,10 @@ public class Elf { return EMPTY_STRING; } + section.makeSureNotCompressed(); StringBuilder str = new StringBuilder(); //Most string symbols will be less than 50 bytes in size byte [] tmp = new byte[50]; - efile.seek(section.sh_offset + index); while(true) { int len = efile.read(tmp); @@ -627,6 +641,7 @@ public class Elf { if (section.sh_type != Section.SHT_DYNAMIC) { return new Dynamic[0]; } + section.makeSureNotCompressed(); ArrayList dynList = new ArrayList(); efile.seek(section.sh_offset); int off = 0; @@ -1066,6 +1081,7 @@ public class Elf { if (section.sh_entsize != 0) { numSyms = (int)section.sh_size / (int)section.sh_entsize; } + section.makeSureNotCompressed(); ArrayList symList = new ArrayList(numSyms); long offset = section.sh_offset; for (int c = 0; c < numSyms; offset += section.sh_entsize, c++) {