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

Fix handling memory of max size on 32-bit systems: check for size_t overflow #808

Merged
merged 2 commits into from
Jan 13, 2022

Conversation

gumb0
Copy link
Collaborator

@gumb0 gumb0 commented Jan 7, 2022

Alternative to #807

@codecov
Copy link

codecov bot commented Jan 7, 2022

Codecov Report

Merging #808 (e9877d8) into only-memory-size-helper (20cb1a0) will decrease coverage by 0.02%.
The diff coverage is 86.95%.

❗ Current head e9877d8 differs from pull request most recent head c5b89ec. Consider uploading reports for the commit c5b89ec to get more accurate results

@@                     Coverage Diff                     @@
##           only-memory-size-helper     #808      +/-   ##
===========================================================
- Coverage                    99.02%   99.00%   -0.03%     
===========================================================
  Files                           81       81              
  Lines                        12825    12845      +20     
===========================================================
+ Hits                         12700    12717      +17     
- Misses                         125      128       +3     
Flag Coverage Δ
rust 99.90% <ø> (ø)
spectests 89.96% <76.92%> (-0.08%) ⬇️
unittests 98.92% <86.95%> (-0.03%) ⬇️

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

Impacted Files Coverage Δ
test/unittests/execute_test.cpp 100.00% <ø> (ø)
lib/fizzy/instantiate.cpp 99.28% <66.66%> (-0.72%) ⬇️
lib/fizzy/execute.cpp 99.17% <80.00%> (-0.12%) ⬇️
lib/fizzy/limits.hpp 100.00% <100.00%> (ø)
test/unittests/instantiate_test.cpp 100.00% <100.00%> (ø)

@gumb0 gumb0 changed the title Max memory 32bit Fix overflows with memory of max size with additional check for size_t overflow Jan 7, 2022
@gumb0 gumb0 changed the base branch from master to only-memory-size-helper January 10, 2022 11:36
@gumb0 gumb0 changed the title Fix overflows with memory of max size with additional check for size_t overflow Fix handling memory of max size on 32-bit systems: check for size_t overflow Jan 10, 2022
@gumb0 gumb0 force-pushed the max-memory-32bit branch 5 times, most recently from bedb050 to 85cf7a8 Compare January 11, 2022 12:29
typename =
typename std::enable_if_t<std::is_integral_v<TypeFrom> && std::is_integral_v<TypeTo> &&
sizeof(TypeFrom) >= sizeof(TypeTo)>>
inline constexpr bool can_narrow_cast(TypeFrom value) noexcept
Copy link
Collaborator Author

@gumb0 gumb0 Jan 11, 2022

Choose a reason for hiding this comment

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

This is not about limits anymore, move to a new header?

return static_cast<uint32_t>(-1);
#pragma clang diagnostic pop
}
if (!can_narrow_cast<size_t>(new_bytes))
Copy link
Collaborator

Choose a reason for hiding this comment

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

The GSL introduced narrow_cast and narrow. The narrow throws exception if conversion changes value. The narrow_cast is just an alias for static_cast so it always succeeds. So probably better name would be can_narrow or can_safely_narrow.

@gumb0 gumb0 force-pushed the max-memory-32bit branch 3 times, most recently from 9bfd43e to e9877d8 Compare January 11, 2022 14:44
@gumb0 gumb0 marked this pull request as ready for review January 11, 2022 14:46
Copy link
Collaborator

@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.

Clean up git history before merge.

@gumb0 gumb0 requested a review from axic January 12, 2022 10:56
Base automatically changed from only-memory-size-helper to master January 13, 2022 10:20
@gumb0 gumb0 merged commit 9d9ed3b into master Jan 13, 2022
@gumb0 gumb0 deleted the max-memory-32bit branch January 13, 2022 10:21
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