lib/vector: Reject out of range categories when reading ASCII - #7844
Open
Pranav-error wants to merge 1 commit into
Open
lib/vector: Reject out of range categories when reading ASCII#7844Pranav-error wants to merge 1 commit into
Pranav-error wants to merge 1 commit into
Conversation
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
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.
Fixes #6563.
Vect_read_ascii()passed the layer and category it parsed straight toVect_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 documented1 - GV_CAT_MAXrange was accepted and stored, and only caused trouble much later.That is what the issue reports: a point carrying
-2147483647was skipped byv.out.ogrwithout-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
Before: imports silently,
v.category ... option=printshows-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.pycovers 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 withDID NOT RAISE CalledModuleErrorand the two happy-path tests pass either way.clang-formatandruffreport no changes.I used an AI assistant while preparing this. I understand the change and can explain it.