Repository navigation
Conversation
The shape of an xtensor<T, N> is a std::array<std::size_t, N>. resize()
checks that a runtime shape has N values, but from_shape() only had an
XTENSOR_ASSERT, off in release builds, and reshape() had no check. A
shape of the wrong length was copied past the std::array, a
stack-buffer-overflow, as in
xtensor<double, 1>::from_shape(std::vector<std::size_t>{2, 3}).
interp() builds its xtensor<T, 1> result with from_shape(x.shape()), so
a 2-D x overflowed the same way, and a 0-D x gave a result with an
uninitialized shape. It also read a 2-D xp or a short fp out of bounds.
from_shape() and both reshape() overloads now use the same
XTENSOR_PRECONDITION as resize(). interp() checks up front that x, xp
and fp are 1-D, that xp is not empty and that fp has the length of xp.
This removes the GCC 13 and 15 -Warray-bounds and -Wmaybe-uninitialized
warnings on the copy into the shape in from_shape(), reached from
interp() in test_extended_xmath_interp.
Contributor
Merging this PR will not alter performance1 warning
Comparing |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Checklist
Description
The shape of an
xtensor<T, N>is astd::array<std::size_t, N>.resizechecks that a runtime shape hasNvalues, butfrom_shapeonly had anXTENSOR_ASSERTandreshapehad no check, so a shape of the wrong length was copied past the array:from_shapeand bothreshapeoverloads now use the sameXTENSOR_PRECONDITIONasresize.interpalso checks its arguments up front:x,xpandfpmust be 1-D,xpmust not be empty, andfpmust have the length ofxp. Before, a 2-Dxpor a shortfpwas read out of bounds, and a 0-Dxgave a result with an uninitialized shape.This removes the GCC 13/15
-Warray-boundsand-Wmaybe-uninitializedwarnings onretinxtensor.hpp(from_shape, reached frominterpintest_extended_xmath_interp).xtensor.change_dimensionandxmath.interp_invalid_argumentsfail on master and pass with the fix, also under AddressSanitizer and UBSan.