diff --git a/lib/evmone/eof.cpp b/lib/evmone/eof.cpp index efcb3784c7..eeb9ff5a7b 100644 --- a/lib/evmone/eof.cpp +++ b/lib/evmone/eof.cpp @@ -83,8 +83,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 240a4bb1bd..071b79e220 100644 --- a/lib/evmone/eof.hpp +++ b/lib/evmone/eof.hpp @@ -36,6 +36,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 cd71dff2e0..66c34e5d77 100644 --- a/test/unittests/eof_validation_test.cpp +++ b/test/unittests/eof_validation_test.cpp @@ -74,3 +74,17 @@ TEST(eof_validation, EOF1_data_section_0_size) EXPECT_EQ(validate_eof(from_hex("EF0001 010001 020000 00 FE")), EOFValidationErrror::zero_section_size); } + +TEST(eof_validation, EOF1_multiple_code_sections) +{ + EXPECT_EQ(validate_eof(from_hex("EF0001 010001 010001 00 FE FE")), + EOFValidationErrror::multiple_code_sections); + EXPECT_EQ(validate_eof(from_hex("EF0001 010001 010001 020001 00 FE FE DA")), + EOFValidationErrror::multiple_code_sections); +} + +TEST(eof_validation, EOF1_multiple_data_sections) +{ + EXPECT_EQ(validate_eof(from_hex("EF0001 010001 020001 020001 00 FE DA DA")), + EOFValidationErrror::multiple_data_sections); +}