Skip to content

fix: return an error for a point without coordinates - #81

Merged
pjsier merged 1 commit into
georust:mainfrom
nikarnik:fix/point-without-coordinates
Nov 20, 2026
Merged

pjsier merged 1 commit into
georust:mainfrom
nikarnik:fix/point-without-coordinates

Conversation

@nikarnik

Copy link
Copy Markdown
Contributor
  • I agree to follow the project's code of conduct.
  • I added an entry to the project's change log file if knowledge of this change could be valuable to users.
    • Usually called CHANGES.md or CHANGELOG.md
    • Prefix changelog entries for breaking changes with "BREAKING: "

Parsing a Point without coordinates panics instead of returning an error:

Kml::<f64>::from_str("<Point></Point>")
thread 'main' panicked at src/reader.rs:309:33:
removal index (is 0) should be < len (is 0)

read_point takes the coordinate with props.coords.remove(0). Before #68, read_geom_props rejected empty coordinates, so this was unreachable. Since #68 (first released in 0.10.0) allows them, inputs such as <Point></Point>, <Point><coordinates /></Point>, or a Placemark with such a point panic. As any document can contain one, the panic can be triggered by untrusted input.

Change

read_point now returns Error::InvalidGeometry("Point must contain a coordinate") when there is no coordinate, like the existing check for a polygon without an outer boundary. Point::coord is not optional, so an error seemed more fitting than a default coordinate. Line strings with empty coordinates still parse, as #68 intended.

Tests

test_parse_point_without_coordinates checks four inputs, including a point nested in a Placemark. Without the fix, it fails with the panic above. cargo test (46 unit, 4 integration, and 12 doc tests), cargo clippy --all-targets, and cargo fmt --check pass.

@pjsier pjsier left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for this! This is a good catch that it became an issue

@pjsier
pjsier merged commit f15a7df into georust:main Nov 20, 2026
9 checks passed
@nikarnik
nikarnik deleted the fix/point-without-coordinates branch November 25, 2026 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants