polygonToCells CLI silently drops vertices when whitespace precedes a coordinate's closing bracket
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 70/100
Research direction
Start in polygonStringToGeoPolygon in src/apps/filters/h3.c, where the coordinate scanner uses the format %lf%*[, \n]%lf%1[]]%n; the ] scanset does not skip whitespace after the second number, so the pair is dropped. Reproduce with h3 polygonToCells -r 5 on the square and the spaced variant, and compare the cell counts (66 vs 34). Done means whitespace before a closing bracket parses the same as without it, and a truly malformed coordinate is rejected rather than silently skipped; also check h3 greatCircleDistanceKm -c '[[0,0],[0,1 ]]'.
Written by the indexing model from the issue text.
Description
On master 15920096, adding one space to a valid coordinate array changes the polygon's covering cells without an error.
Reproduction
Using the native CLI built from unchanged source with GCC 14.2.0 on Linux:
h3 polygonToCells -r 5 -p '[[0,0],[0,1],[1,1],[1,0]]' > square.json
h3 polygonToCells -r 5 -p '[[0,0],[0,1],[1,1 ],[1,0]]' > spaced.json
h3 polygonToCells -r 5 -p '[[0,0],[0,1],[1,0]]' > triangle.json
python3 - <<'PY'
import json
square = set(json.load(open('square.json')))
spaced = set(json.load(open('spaced.json')))
triangle = set(json.load(open('triangle.json')))
print(len(square), len(spaced), len(triangle))
print(spaced == square, spaced == triangle)
PY
# 66 34 34
# False True
All three CLI invocations exit with status 0. The second input describes the same four corners as the first, but its result exactly matches the triangle with [1,1] removed. This can silently change the covered region when coordinate arrays are reformatted.
Expected
Whitespace between a number and ] should not change the coordinates or covering cells. If a coordinate cannot be parsed, the CLI should reject the input rather than silently omit it.
Investigation and controls
The coordinate scanner in polygonStringToGeoPolygon uses %lf%*[, \n]%lf%1[]]%n. The scanset for ] does not skip whitespace after the second number; the coordinate is not appended when that conversion fails.
I reproduced the same 34-cell result with a tab, line feed or carriage return before that closing bracket. Spaces after coordinate brackets preserve the expected 66-cell result. Python's JSON parser confirms that the four whitespace variants describe the same coordinate array as the original.
The same parser also affects distance input: h3 greatCircleDistanceKm -c '[[0,0],[0,1]]' prints 111.1950519752, while adding a space before the second coordinate's closing bracket produces Only two pairs of coordinates should be provided.
This is a short inline-input case, not the 1500-byte file-chunk boundary fixed by #1249. No library API change or patch is proposed here. Validation is limited to the native Linux/GCC CLI and the controls above; I have not run the full CTest suite or tested other platforms.
- Dominant language
- C
- Stars
- 6.7k
- Forks
- 658
- Avg merge
- 5d 21h
- Merged PRs (30d)
- 12
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from uber/h3
-
cellsToMultiPolygon: int64_t counts are narrowed to int struct fields without a bounds checkPossibly taken @madib06ops claimed this 30 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
Difficulty 3/5 Half a day Newbie friendliness 45/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 50/100
Maintainers usually reply within 1 day
-
Difficulty 3/5 Half a day Newbie friendliness 45/100
Maintainers usually reply within 1 day
Similar issues
-
Status: Opened
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
FriendsofECCE/ECCE#1018 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
immortalwrt/immortalwrt#2522 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
severity: low
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
luainkernel/lunatik#2530 ·
Maintainers usually reply within 1 day