Skip to content

Commit

Permalink
Merge pull request #173 from haberman/fuzz
Browse files Browse the repository at this point in the history
Fuzz fixes.
  • Loading branch information
haberman authored Sep 1, 2019
2 parents 3fd3e9a + d35fb81 commit f8e2914
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/elf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,12 @@ void ForEachElf(const InputFile& file, RangeSink* sink, Func func) {
// - 40 bits for address (up to 1TB section)
static uint64_t ToVMAddr(size_t addr, long ndx, bool is_object) {
if (is_object) {
if (ndx >= 1 << 24) {
THROW("ndx overflow: too many sections");
}
if (addr >= 1UL << 40) {
THROW("address overflow: section too big");
}
return (ndx << 40) | addr;
} else {
return addr;
Expand Down
12 changes: 5 additions & 7 deletions src/webassembly.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,22 +118,20 @@ class Section {

ret.id = ReadVarUInt7(&data);
uint32_t size = ReadVarUInt32(&data);
string_view next_section = data.substr(size);
data = data.substr(0, size);
size_t header_size = data.data() - section_data.data();
ret.contents = ReadPiece(size, &data);
size_t header_size = ret.contents.data() - section_data.data();
ret.data = section_data.substr(0, size + header_size);

if (ret.id == 0) {
uint32_t name_len = ReadVarUInt32(&data);
ret.name = std::string(ReadPiece(name_len, &data));
uint32_t name_len = ReadVarUInt32(&ret.contents);
ret.name = std::string(ReadPiece(name_len, &ret.contents));
} else if (ret.id <= 11) {
ret.name = names[ret.id];
} else {
THROWF("Unknown section id: $0", ret.id);
}

ret.contents = data;
*data_param = next_section;
*data_param = data;
return ret;
}

Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit f8e2914

Please sign in to comment.