Skip to content

Add cross-dimension shape validation for diff prepend/append#1152

Merged
jalvesz merged 5 commits into
fortran-lang:masterfrom
srinjoy933:fix-diff2-bounds-check
Mar 26, 2026
Merged

Add cross-dimension shape validation for diff prepend/append#1152
jalvesz merged 5 commits into
fortran-lang:masterfrom
srinjoy933:fix-diff2-bounds-check

Conversation

@srinjoy933
Copy link
Copy Markdown
Contributor

This PR introduces explicit cross-dimension shape validation for the prepend and append arguments in the diff_2 routine. Previously, passing an array with a mismatched non-differencing dimension bypassed shape checks, leading to potential bounds-check faults or silent memory corruption during the internal work array assignment. The update verifies size(array, 3 - dim_) == size(x, 3 - dim_) prior to workspace allocation, ensuring safe execution.
Solves #1151

@srinjoy933
Copy link
Copy Markdown
Contributor Author

@jvdp1 @jalvesz please review this pr once, kindly give me your suggestions whether any changes are required or not. Thank You!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds explicit cross-dimension (non-differencing dimension) shape validation for diff_2’s optional prepend/append arguments to prevent out-of-bounds assignment/memory corruption scenarios described in #1151.

Changes:

  • Validate size(prepend, 3-dim_) == size(x, 3-dim_) before using prepend in the internal workspace.
  • Validate size(append, 3-dim_) == size(x, 3-dim_) before using append in the internal workspace.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/math/stdlib_math_diff.fypp
Comment thread src/math/stdlib_math_diff.fypp
Comment thread src/math/stdlib_math_diff.fypp
Comment thread src/math/stdlib_math_diff.fypp
Comment thread src/math/stdlib_math_diff.fypp Outdated
Comment thread src/math/stdlib_math_diff.fypp Outdated
@srinjoy933 srinjoy933 force-pushed the fix-diff2-bounds-check branch from 5648b0c to 99a460a Compare March 24, 2026 19:23
@srinjoy933 srinjoy933 requested a review from jalvesz March 24, 2026 19:34
@srinjoy933
Copy link
Copy Markdown
Contributor Author

hey @jalvesz according to the suggestion you have given I have raised a updated pr. Please have a look on this and suggest if there is requirement of any further changes

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.00%. Comparing base (ac98d3b) to head (99a460a).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1152   +/-   ##
=======================================
  Coverage   68.00%   68.00%           
=======================================
  Files         404      404           
  Lines       12935    12935           
  Branches     1392     1392           
=======================================
  Hits         8797     8797           
  Misses       4138     4138           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Member

@jvdp1 jvdp1 left a comment

Choose a reason for hiding this comment

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

thank you @srinjoy933 . LGTM!

@jalvesz jalvesz merged commit fb63d7e into fortran-lang:master Mar 26, 2026
77 checks passed
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.

4 participants