-
Notifications
You must be signed in to change notification settings - Fork 223
Description
Hey everyone, I was looking through the stdlib_math_diff submodule and noticed a potential array bounds vulnerability in diff_2 regarding the optional prepend and append arguments. Currently, the routine allocates the internal work array based on the orthogonal dimension of the input array x (for instance, using size(x, 2) when dim_ = 1), but it completely skips validating the shape of prepend or append along that non-differencing dimension. If a downstream user accidentally passes a prepend array with a mismatched cross-dimension, the assignment step (e.g., work(1:size_prepend, :) = prepend) will trigger a fatal runtime bounds-check error or cause silent memory corruption depending on their compiler flags.
we should probably add a quick shape validation check right after checking present(prepend) or present(append) to ensure the non-differenced dimensions match x perfectly, triggering an explicit error stop .