Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eof: Fix CALLF runtime stack overflow check #677

Merged
merged 2 commits into from
Jul 31, 2023

Conversation

gumb0
Copy link
Member

@gumb0 gumb0 commented Jul 28, 2023

We were double counting the callee's inputs (both current stack height and callee's max_stack_height include inputs)

(Similar fix is needed for validation-time check and for JUMPF, but those are not merged yet)

@gumb0
Copy link
Member Author

gumb0 commented Jul 31, 2023

@gumb0 gumb0 marked this pull request as ready for review July 31, 2023 10:52
@codecov
Copy link

codecov bot commented Jul 31, 2023

Codecov Report

Merging #677 (837ddea) into master (bc4eefb) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #677      +/-   ##
==========================================
+ Coverage   97.43%   97.45%   +0.01%     
==========================================
  Files          83       83              
  Lines        8042     8065      +23     
==========================================
+ Hits         7836     7860      +24     
+ Misses        206      205       -1     
Flag Coverage Δ
blockchaintests 62.90% <0.00%> (-0.05%) ⬇️
statetests 74.07% <100.00%> (-0.04%) ⬇️
statetests-silkpre 23.52% <9.09%> (-0.05%) ⬇️
unittests 94.92% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
lib/evmone/instructions.hpp 100.00% <100.00%> (ø)
test/unittests/evm_eof_function_test.cpp 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

Copy link
Member

@chfast chfast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix description should also go to the commit message.

@@ -1025,7 +1025,8 @@ inline code_iterator callf(StackTop stack, ExecutionState& state, code_iterator
const auto index = read_uint16_be(&pos[1]);
const auto& header = state.analysis.baseline->eof_header;
const auto stack_size = &stack.top() - state.stack_space.bottom();
if (stack_size + header.types[index].max_stack_height > StackSpace::limit)
if (stack_size + header.types[index].max_stack_height - header.types[index].inputs >
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add variable const auto callee_required_stack_size = header.types[index].max_stack_height - header.types[index].inputs;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

Current stack height and callee's max_stack_height include inputs, we must not double-count them.
@gumb0 gumb0 force-pushed the callf-stackoverflow-runtime-check branch from 2b6f009 to 837ddea Compare July 31, 2023 14:53
@chfast chfast merged commit 7bb3aa2 into master Jul 31, 2023
@chfast chfast deleted the callf-stackoverflow-runtime-check branch July 31, 2023 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants