Skip to content

Commit 9e61fe1

Browse files
committed
eof: Move stray bytes check into validate_section_header()
This is simplification, it is more natural to check it together with the check for truncated body. This check was earlier moved into higher-level function to allow for stray bytes in EOF Creation Transactions.
1 parent 16ed652 commit 9e61fe1

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

lib/evmone/eof.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,12 @@ std::variant<EOFSectionHeaders, EOFValidationError> validate_section_headers(byt
225225
std::accumulate(section_headers.container_sizes.begin(),
226226
section_headers.container_sizes.end(), uint64_t{0});
227227
const auto remaining_container_size = static_cast<uint64_t>(container_end - it);
228-
// Only data section may be truncated, so remaining_container size must be at least
229-
// declared_size_without_data
228+
// Only data section may be truncated, so remaining_container size must be in
229+
// [declared_size_without_data, declared_size_without_data + declared_data_size]
230230
if (remaining_container_size < section_bodies_without_data)
231231
return EOFValidationError::invalid_section_bodies_size;
232+
if (remaining_container_size > section_bodies_without_data + section_headers.data_size)
233+
return EOFValidationError::invalid_section_bodies_size;
232234

233235
return section_headers;
234236
}
@@ -632,9 +634,6 @@ EOFValidationError validate_eof1(
632634

633635
auto& header = std::get<EOF1Header>(error_or_header);
634636

635-
if (container.size() > static_cast<size_t>(header.data_offset) + header.data_size)
636-
return EOFValidationError::invalid_section_bodies_size;
637-
638637
if (const auto err = validate_types(container, header); err != EOFValidationError::success)
639638
return err;
640639

0 commit comments

Comments
 (0)