Conversation
gmtio_align_ogr_values() stored gmt_get_ogr_id()'s GMT_NOTSET (-1) return value unchecked into GMT->common.a.ogr[], which was later used as an array index (e.g. T[GMT->common.a.ogr[col]] in gmtio_build_text_from_ogr()) whenever -a<flag>=<name> named a field that does not exist in the OGR/shapefile attribute table. This read out of bounds and either crashed directly in strncat() or corrupted the segment header buffer, crashing later in gmt_parse_segment_header() -- matching both stack traces in the report. A validation for this exact case already existed in gmtio_select_all_ogr_if_requested(), but it only runs once the first data record's column types are examined, which is after the crash already occurs while processing the first segment header. Move the check to where the index is computed so it fires before any use, and also mark the record-loop's associated bail-out path as EOF so the resulting error is reported once instead of once per record. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…hout -C The issue's third repro used a *valid* aspatial field name (-aZ=POP_EST) but omitted -C. plot/psxy and psxyz initialize their CPT pointer P to NULL until -C is parsed. gmt_parse_segment_header()'s OGR/aspatial branch dereferenced P unconditionally in the GMT_IS_Z case (P->categorical), crashing with SIGSEGV in gmt_parse_segment_header - matching the second stack trace in the report. The plain (non-aspatial) -Z branch just below already guards the equivalent lookup with `if (P && ...)`; the aspatial branch was missing the same guard. Added the same guard at the point of use in gmt_io.c, and also added an early, clear validation error in psxy.c/psxyz.c's option parsing (mirroring the existing "Option -Z: No CPT given via -C" check) so users seeing -a<flag>=Z without -C get a helpful message and a non-zero exit code instead of silently plotting without color or (previously) crashing. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
joa-quim
approved these changes
Aug 27, 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.
Issue:
plotcrashes with a segfault when-areferences an aspatial field name that doesn't exist in the shapefile, or when-aZ=<field>is used without-C. With this fix, now fail with a clear error message instead:@seisman are those messages ok?
Fixes #9153
Done with Sonnet 5