ethereum / evmone

Fast Ethereum Virtual Machine implementation
Apache License 2.0
865 stars 287 forks source link

EOF: Assert against overflow in header.data_offset #891

Closed pdobacz closed 6 months ago

pdobacz commented 6 months ago

While working on #878 I noticed the offset calculation in validate_header can overflow the uint16, if the declared sizes of container sections are large. Currently there is no upper limit on container size in validation (there's only the indirect limit imposed by max_initcode_size), so there can be a large container, which has a subcontainer of size 0xffff, and will have it's data_offset not fit the uint16.

We have 2 tests which happened to run into this, but the problem was masked (the data_offset was just really tiny, despite the container had a huge subcontainer, but it was never used, and the check for stray data wasn't affected by the overflow). I adjust them so (IMO) they still test what they're supposed to test, but not overflow.

codecov[bot] commented 6 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Please upload report for BASE (master@7f65121). Learn more about missing BASE report.

:exclamation: Current head 93d42c5 differs from pull request most recent head 282f575

Please upload reports for the commit 282f575 to get more accurate results.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #891 +/- ## ========================================= Coverage ? 98.49% ========================================= Files ? 130 Lines ? 15630 Branches ? 0 ========================================= Hits ? 15394 Misses ? 236 Partials ? 0 ``` | [Flag](https://app.codecov.io/gh/ethereum/evmone/pull/891/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum) | Coverage Δ | | |---|---|---| | [ethereum-tests](https://app.codecov.io/gh/ethereum/evmone/pull/891/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum) | `27.95% <9.09%> (?)` | | | [ethereum-tests-silkpre](https://app.codecov.io/gh/ethereum/evmone/pull/891/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum) | `19.69% <0.00%> (?)` | | | [execution-spec-tests](https://app.codecov.io/gh/ethereum/evmone/pull/891/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum) | `19.05% <0.00%> (?)` | | | [unittests](https://app.codecov.io/gh/ethereum/evmone/pull/891/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum) | `94.34% <100.00%> (?)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files](https://app.codecov.io/gh/ethereum/evmone/pull/891?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum) | Coverage Δ | | |---|---|---| | [lib/evmone/eof.cpp](https://app.codecov.io/gh/ethereum/evmone/pull/891?src=pr&el=tree&filepath=lib%2Fevmone%2Feof.cpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum#diff-bGliL2V2bW9uZS9lb2YuY3Bw) | `87.33% <100.00%> (ø)` | | | [test/unittests/eof\_validation\_test.cpp](https://app.codecov.io/gh/ethereum/evmone/pull/891?src=pr&el=tree&filepath=test%2Funittests%2Feof_validation_test.cpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum#diff-dGVzdC91bml0dGVzdHMvZW9mX3ZhbGlkYXRpb25fdGVzdC5jcHA=) | `100.00% <100.00%> (ø)` | | | [...est/unittests/state\_transition\_eof\_create\_test.cpp](https://app.codecov.io/gh/ethereum/evmone/pull/891?src=pr&el=tree&filepath=test%2Funittests%2Fstate_transition_eof_create_test.cpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ethereum#diff-dGVzdC91bml0dGVzdHMvc3RhdGVfdHJhbnNpdGlvbl9lb2ZfY3JlYXRlX3Rlc3QuY3Bw) | `100.00% <100.00%> (ø)` | |