From 8251d3430f8ef19591b5f41eb8665e9715bd719f Mon Sep 17 00:00:00 2001 From: pdobacz <5735525+pdobacz@users.noreply.github.com> Date: Tue, 25 Jun 2024 13:31:13 +0200 Subject: [PATCH] Address feedback in `validate_header` --- lib/evmone/eof.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/evmone/eof.cpp b/lib/evmone/eof.cpp index 69b920620b..a5e2f343cd 100644 --- a/lib/evmone/eof.cpp +++ b/lib/evmone/eof.cpp @@ -745,6 +745,12 @@ std::variant validate_header( if (rev < EVMC_PRAGUE) return EOFValidationError::eof_version_unknown; + // `offset` variable handled below is known to not be greater than the container size, as + // checked in `validate_section_headers`. Combined with the requirement for the container + // size to not exceed MAX_INITCODE_SIZE (checked before `validate-header` is called), + // this allows us to cast `offset` to narrower integers. + assert(container.size() <= MAX_INITCODE_SIZE); + const auto section_headers_or_error = validate_section_headers(container); if (const auto* error = std::get_if(§ion_headers_or_error)) return *error; @@ -765,11 +771,6 @@ std::variant validate_header( const auto type_section_size = section_headers[TYPE_SECTION][0]; auto offset = header_size + type_section_size; - // `offset` is being checked to not overflow the container size. NOTE: this is done - // implicitly in `validate_section_headers` above. Combined with the - // requirement for the container size to not exceed MAX_INITCODE_SIZE, this allows - // us to cast to a narrower integer. - for (const auto code_size : code_sizes) { assert(offset <= std::numeric_limits::max()); @@ -784,7 +785,6 @@ std::variant validate_header( container_offsets.emplace_back(static_cast(offset)); offset += container_size; } - const auto data_offset = static_cast(offset); return EOF1Header{