Skip to content

Commit

Permalink
Resolve #976
Browse files Browse the repository at this point in the history
  • Loading branch information
romainthomas committed Oct 7, 2023
1 parent d7b962d commit d5dc7fd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Abstract/Section.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ std::vector<size_t> Section::search_all(const std::string& v) const {
double Section::entropy() const {
std::array<uint64_t, 256> frequencies = { {0} };
span<const uint8_t> content = this->content();
if (content.empty()) {
if (content.empty() || content.size() == 1) {
return 0.;
}
for (uint8_t x : content) {
Expand Down
12 changes: 12 additions & 0 deletions tests/abstract/test_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,15 @@ def test_function():
assert binary.get_function_address("foo") == lief.lief_errors.not_found
assert binary.get_function_address("add") == 0x6a0


def test_entropy():
"""
from issue #976 by @PaulDance
"""
weird_section_0 = lief.MachO.Section("weird_section_0", []).entropy
weird_section_1 = lief.MachO.Section("weird_section_1", [1]).entropy
assert str(weird_section_0) == "0.0"
assert str(weird_section_1) == "0.0"

assert weird_section_0 >= 0
assert weird_section_1 >= 0

0 comments on commit d5dc7fd

Please sign in to comment.