1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 14:12:10 +02:00

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 <marc-andre.laperle@ericsson.com>
This commit is contained in:
Marc-Andre Laperle 2018-06-18 11:13:23 -04:00 committed by Marc-André Laperle
parent 836db69fb8
commit 00df140228
3 changed files with 26 additions and 2 deletions

View file

@ -68,4 +68,12 @@
</message_arguments> </message_arguments>
</filter> </filter>
</resource> </resource>
<resource path="utils/org/eclipse/cdt/utils/elf/Elf.java" type="org.eclipse.cdt.utils.elf.Elf$Section">
<filter comment="Unlikely API incompatibility" id="336658481">
<message_arguments>
<message_argument value="org.eclipse.cdt.utils.elf.Elf.Section"/>
<message_argument value="SHF_COMPRESSED"/>
</message_arguments>
</filter>
</resource>
</component> </component>

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2 Bundle-ManifestVersion: 2
Bundle-Name: %pluginName Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.core; singleton:=true 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-Activator: org.eclipse.cdt.core.CCorePlugin
Bundle-Vendor: %providerName Bundle-Vendor: %providerName
Bundle-Localization: plugin Bundle-Localization: plugin

View file

@ -302,6 +302,10 @@ public class Elf {
public final static int SHF_WRITE = 1; public final static int SHF_WRITE = 1;
public final static int SHF_ALLOC = 2; public final static int SHF_ALLOC = 2;
public final static int SHF_EXECINTR = 4; public final static int SHF_EXECINTR = 4;
/**
* @since 6.6
*/
public final static int SHF_COMPRESSED = 2048;
/* note_types */ /* note_types */
/** /**
@ -324,17 +328,26 @@ public class Elf {
* @since 5.1 * @since 5.1
*/ */
public ByteBuffer mapSectionData() throws IOException { public ByteBuffer mapSectionData() throws IOException {
makeSureNotCompressed();
sections_mapped = true; sections_mapped = true;
return efile.getChannel().map(MapMode.READ_ONLY, sh_offset, sh_size).load().asReadOnlyBuffer(); return efile.getChannel().map(MapMode.READ_ONLY, sh_offset, sh_size).load().asReadOnlyBuffer();
} }
public byte[] loadSectionData() throws IOException { public byte[] loadSectionData() throws IOException {
makeSureNotCompressed();
byte[] data = new byte[(int)sh_size]; byte[] data = new byte[(int)sh_size];
efile.seek(sh_offset); efile.seek(sh_offset);
efile.read(data); efile.read(data);
return 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 @Override
public String toString() { public String toString() {
try { try {
@ -342,6 +355,7 @@ public class Elf {
final int shstrndx= ehdr.e_shstrndx & 0xffff; // unsigned short final int shstrndx= ehdr.e_shstrndx & 0xffff; // unsigned short
if (shstrndx > sections.length || shstrndx < 0) if (shstrndx > sections.length || shstrndx < 0)
return EMPTY_STRING; return EMPTY_STRING;
sections[shstrndx].makeSureNotCompressed();
int size = (int)sections[shstrndx].sh_size; int size = (int)sections[shstrndx].sh_size;
if (size <= 0 || size > efile.length()) if (size <= 0 || size > efile.length())
return EMPTY_STRING; return EMPTY_STRING;
@ -367,10 +381,10 @@ public class Elf {
return EMPTY_STRING; return EMPTY_STRING;
} }
section.makeSureNotCompressed();
StringBuilder str = new StringBuilder(); StringBuilder str = new StringBuilder();
//Most string symbols will be less than 50 bytes in size //Most string symbols will be less than 50 bytes in size
byte [] tmp = new byte[50]; byte [] tmp = new byte[50];
efile.seek(section.sh_offset + index); efile.seek(section.sh_offset + index);
while(true) { while(true) {
int len = efile.read(tmp); int len = efile.read(tmp);
@ -627,6 +641,7 @@ public class Elf {
if (section.sh_type != Section.SHT_DYNAMIC) { if (section.sh_type != Section.SHT_DYNAMIC) {
return new Dynamic[0]; return new Dynamic[0];
} }
section.makeSureNotCompressed();
ArrayList<Dynamic> dynList = new ArrayList<Dynamic>(); ArrayList<Dynamic> dynList = new ArrayList<Dynamic>();
efile.seek(section.sh_offset); efile.seek(section.sh_offset);
int off = 0; int off = 0;
@ -1066,6 +1081,7 @@ public class Elf {
if (section.sh_entsize != 0) { if (section.sh_entsize != 0) {
numSyms = (int)section.sh_size / (int)section.sh_entsize; numSyms = (int)section.sh_size / (int)section.sh_entsize;
} }
section.makeSureNotCompressed();
ArrayList<Symbol> symList = new ArrayList<Symbol>(numSyms); ArrayList<Symbol> symList = new ArrayList<Symbol>(numSyms);
long offset = section.sh_offset; long offset = section.sh_offset;
for (int c = 0; c < numSyms; offset += section.sh_entsize, c++) { for (int c = 0; c < numSyms; offset += section.sh_entsize, c++) {