Skip to content

Missing cross-dimension shape validation for prepend/append in diff_2 #1151

@srinjoy933

Description

@srinjoy933

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 .

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions