Fix out-of-bounds read in egs_view
by making region arrays the same size
#756
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
After compiling
egs_view
with asan support, there was a buffer overflowerror encountered opening
tutor7pp/test1.egsinp
.It was traced back to the memcpy call in
ImageWindow::paintEvent
:The issue is that memcpy will always copy
sizeof(lastRegions)
bytes fromregions
,into
lastRegions
, but before this changeregions
could be potentiallyshorter than
lastRegions
, making part of the read out of bounds.After this change,
maxreg
is always set toN_REG_MAX
, the length oflastRegions
.EGSnrc/HEN_HOUSE/egs++/view/image_window.cpp
Lines 338 to 347 in a6fc389
This effectively reverts part of 246ee26, where the size of
regions
was changed to scale the region list when the window was resized (perhaps there is a better resolution that keeps this feature, I thought I would try the simplest resolution for now).Reproduction
Compile
egs_view
with asan support by uncommenting the following lines:EGSnrc/HEN_HOUSE/egs++/view/view.pro
Lines 91 to 94 in a6fc389
Full debug log and asan output