diff --git a/lib/evmone/eof.cpp b/lib/evmone/eof.cpp index 0d5a7ba73a..8a92578383 100644 --- a/lib/evmone/eof.cpp +++ b/lib/evmone/eof.cpp @@ -93,8 +93,13 @@ std::pair validate_eof1( case DATA_SECTION: if (section_sizes[CODE_SECTION] == 0) return {{}, EOFValidationErrror::code_section_missing}; - [[fallthrough]]; + if (section_sizes[DATA_SECTION] != 0) + return {{}, EOFValidationErrror::multiple_data_sections}; + state = State::section_size; + break; case CODE_SECTION: + if (section_sizes[CODE_SECTION] != 0) + return {{}, EOFValidationErrror::multiple_code_sections}; state = State::section_size; break; default: diff --git a/lib/evmone/eof.hpp b/lib/evmone/eof.hpp index ac2eb5e332..b14a3adfd4 100644 --- a/lib/evmone/eof.hpp +++ b/lib/evmone/eof.hpp @@ -37,6 +37,8 @@ enum class EOFValidationErrror incomplete_section_size, code_section_missing, + multiple_code_sections, + multiple_data_sections, unknown_section_id, zero_section_size, section_headers_not_terminated, diff --git a/test/unittests/eof_validation_test.cpp b/test/unittests/eof_validation_test.cpp index 78f26adaf3..ddd811cd6e 100644 --- a/test/unittests/eof_validation_test.cpp +++ b/test/unittests/eof_validation_test.cpp @@ -69,3 +69,17 @@ TEST(eof_validation, EOF1_code_section_missing) EXPECT_EQ(validate_eof(EVMC_SHANGHAI, from_hex("EFCAFE01 020001 DA")), EOFValidationErrror::code_section_missing); } + +TEST(eof_validation, EOF1_multiple_code_sections) +{ + EXPECT_EQ(validate_eof(EVMC_SHANGHAI, from_hex("EFCAFE01 010001 010001 00 FE FE")), + EOFValidationErrror::multiple_code_sections); + EXPECT_EQ(validate_eof(EVMC_SHANGHAI, from_hex("EFCAFE01 010001 010001 020001 00 FE FE DA")), + EOFValidationErrror::multiple_code_sections); +} + +TEST(eof_validation, EOF1_multiple_data_sections) +{ + EXPECT_EQ(validate_eof(EVMC_SHANGHAI, from_hex("EFCAFE01 010001 020001 020001 00 FE DA DA")), + EOFValidationErrror::multiple_data_sections); +}