Skip to content

Commit

Permalink
Resolve #1055
Browse files Browse the repository at this point in the history
  • Loading branch information
romainthomas committed May 6, 2024
1 parent 132ac2d commit 807b257
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/MachO/Section.cpp
Expand Up @@ -117,7 +117,6 @@ void Section::swap(Section& other) {

}


Section::Section(std::string name) {
this->name(std::move(name));
}
Expand All @@ -136,6 +135,10 @@ span<const uint8_t> Section::content() const {
return {};
}

if (int64_t(size_) < 0 || int64_t(offset_) < 0) {
return {};
}

uint64_t relative_offset = offset_ - segment_->file_offset();
span<const uint8_t> content = segment_->content();
if (relative_offset > content.size() || (relative_offset + size_) > content.size()) {
Expand Down
6 changes: 6 additions & 0 deletions tests/macho/test_generic.py
Expand Up @@ -280,3 +280,9 @@ def test_twolevel_hints():
def test_overlay():
sample = lief.MachO.parse(get_sample("MachO/overlay_data.bin")).at(0)
assert bytes(sample.overlay) == b'\x00overlay data'

def test_issue_1055():
sample = lief.MachO.parse(get_sample("MachO/issue_1055.bin")).at(0)
for section in sample.sections:
size = len(section.content)
assert size is not None

0 comments on commit 807b257

Please sign in to comment.