Repository navigation
gmtgravmag3d: Fix heap out-of-bounds read in read_xyz - #9308
Merged
Merged
Conversation
The loop that computes the central latitude of geographic -T input read Ctrl->triang[n].y (one past the end of the array, which was just reallocated to n elements) instead of Ctrl->triang[k].y. When the garbage value exceeded +/-FLT_MAX, lat_0 became huge, all y coordinates collapsed to the same value and the computed anomaly was exactly zero. This is why test/potential/fc_okb.sh failed intermittently on macOS CI. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
joa-quim
approved these changes
Nov 18, 2026
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.
I asked Claude to analyze why the test
fc_okb.shfailed on macOS.Cause and fix
Claude proposes this fix.
In
read_xyz, the loop that finds the latitude range of geographic input readsCtrl->triang[n].yinstead ofCtrl->triang[k].y.trianghas just been reallocated to exactlynelements, so this reads 8 bytes past the end of the array (bug from 8dab545, 2020).Usually that stray value is harmless and the result is correct. When it happens to be larger than
±FLT_MAX,lat_0becomes huge, every y coordinate collapses to the same value, the triangles become degenerate and the anomaly is exactly 0.Test
I tested it running
gmtgravmag3dfrom the test under valgrind:On master I get this output:
And this with the fix:
Generated using Claude Opus 5.5.