Fix crashes reading records with too few columns - #9231
Merged
Merged
Conversation
gmtlib_read_table deletes a segment whose records were all skipped for having too few columns, and steps back with seg--. When that is the first segment, seg (a uint64_t) wraps to UINT64_MAX and T->segment[seg] is read out of bounds. This happens when every record of a headerless first segment, possibly the whole file, is too short; a file that starts with a segment header never gets here. Start over from the first segment instead, so the table reads as if those records were not there. Tested with: printf '30 45\n120 60\n' | gmt convert -i0:2 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Polygon closure and the one-time line/polygon detection ran before the empty segment was deleted. On an emptied first segment the closure dereferenced coordinate arrays that were not allocated yet, so gmt spatial -Fp segfaulted; with geographic data and arrays left over from a previous file it read x[row-1] out of bounds and kept a phantom one-point segment of stale data. The detection was also spent on the empty segment, so the polygons that followed were read as lines and left open: gmt info -Fi counted 7 records instead of 8. Skip both for an empty segment. Tested with: printf '1 2\n> P1\n0 0 1\n10 0 1\n10 10 1\n' | gmt spatial -Fp -i0:2 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After a good record the read loop skips comment lines, but the branch that reads on after a too-short record did not. A comment right after such a record left In NULL, and the loop then copied In->data. Tested with: printf '1 2 3\n4 5\n# c\n6 7 8\n' | gmt convert Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
Author
|
The outputs with this fix are: |
Esteban82
marked this pull request as ready for review
September 27, 2026 15:08
joa-quim
approved these changes
Sep 28, 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.
gmtlib_read_table(src/gmt_io.c) skips records with fewer columns than requested, but crashes when they empty the first segment (an unsignedseg--wraps), when that segment is then read as a polygon, and when a comment follows such a record. One commit per crash, each with a test.Tested with:
Assisted-by: Claude Opus 5.5 (max effort); tests first drafted with Claude Sonnet 5 and reviewed with Opus.
🤖 Generated with Claude Code