Skip to content

lib/vector: Reject out of range categories when reading ASCII - #7844

Open
Pranav-error wants to merge 1 commit into
OSGeo:mainfrom
Pranav-error:fix-ascii-negative-cat
Open

lib/vector: Reject out of range categories when reading ASCII#7844
Pranav-error wants to merge 1 commit into
OSGeo:mainfrom
Pranav-error:fix-ascii-negative-cat

Conversation

@Pranav-error

Copy link
Copy Markdown
Contributor

Fixes #6563.

Vect_read_ascii() passed the layer and category it parsed straight to Vect_cat_set(). That function's own range check is commented out — deliberately, with a note about the portable type length — so a value outside the documented 1 - GV_CAT_MAX range was accepted and stored, and only caused trouble much later.

That is what the issue reports: a point carrying -2147483647 was skipped by v.out.ogr without -c, and exported twice with it.

@metzm's comment on the issue identified the real cause — negative categories should not have been accepted in the first place — so this rejects the feature at import rather than trying to make the export cope with it.

Category 0 stays allowed, since OGR layers use it (per "Categories and Layers" in the Programmer's Manual). Layer numbers start at 1, so 0 is rejected.

Reproducing it

printf "P 1 1\n0 0\n1 1\nP 1 1\n1 0\n1 -2147483647\n" | \
  v.in.ascii -n input=- output=pts format=standard

Before: imports silently, v.category ... option=print shows -2147483647.
After: WARNING: Layer number or category number out of range: [1 -2147483647] and the import fails.

Tests

vector/v.in.ascii/tests/v_in_ascii_categories_test.py covers the negative category and layer 0 being rejected, plus ordinary categories and category 0 still importing. Checked against the unfixed build, where the two rejection tests fail with DID NOT RAISE CalledModuleError and the two happy-path tests pass either way. clang-format and ruff report no changes.

I used an AI assistant while preparing this. I understand the change and can explain it.

Vect_read_ascii() passed the layer and category straight to
Vect_cat_set(), whose own range check is commented out, so a value outside
the documented 1 - GV_CAT_MAX range was stored and only caused trouble
later. A point carrying a negative category was skipped by v.out.ogr
without -c and exported twice with it.

Reject the feature at import instead. Category 0 stays allowed, since OGR
layers use it.

Fixes OSGeo#6563
Copilot AI lite review requested due to automatic review settings August 24, 2026 14:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added vector Related to vector data processing Python Related code is in Python C Related code is in C libraries module tests Related to Test Suite labels Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C Related code is in C libraries module Python Related code is in Python tests Related to Test Suite vector Related to vector data processing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] v.out.ogr export points w/ missing category twice

2 participants