Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic in tile38 causing server crash due to bug in geojson #714

Closed
prathik opened this issue Dec 18, 2023 · 2 comments
Closed

Panic in tile38 causing server crash due to bug in geojson #714

prathik opened this issue Dec 18, 2023 · 2 comments

Comments

@prathik
Copy link

prathik commented Dec 18, 2023

Describe the bug
If we put a geojson with some polygons having z coordinates and others not having them, then the way geojson currently handles it would head to a panic and the server crash.

Here is the related PR on geojson that would fix the panic (but not the issue)
tidwall/geojson#26

To Reproduce
Steps to reproduce the behavior:

Run the following commands

> set abc test object {"type":"Polygon","coordinates":[[[0,0],[10,0],[0,10],[0,0]],[[0,0,0],[0,10,0],[10,0,0],[0,0,0]]]}

> get abc test

This leads to tile38-server crashing.

Expected behavior

Tile38 should respond with

{"ok":true,"object":{"type":"Polygon","coordinates":[[[0,0],[10,0],[0,10],[0,0]],[[0,0,0],[0,10,0],[10,0,0],[0,0,0]]]},"elapsed":"17.224µs"}

Logs

panic: runtime error: index out of range [4] with length 4

goroutine 40 [running]:
github.com/tidwall/geojson.appendJSONPoint({0xc000044300?, 0xc000406670?, 0x
105378f?}, {0x30?, 0x0?}, 0xc000002750, 0x4)
        github.com/tidwall/geojson@v1.4.3/object.go:261 +0x168
github.com/tidwall/geojson.appendJSONSeries({0xc000044300?, 0x1?, 0xc0004066
c8?}, {0x217c6d0, 0xc0000cccd0}, 0x2f01878?, 0x4)
        github.com/tidwall/geojson@v1.4.3/object.go:293 +0xe5
github.com/tidwall/geojson.(*Polygon).AppendJSON(0xc000002780, {0x0?, 0x0?,
0x4?})
        github.com/tidwall/geojson@v1.4.3/polygon.go:48 +0x1b9
github.com/tidwall/tile38/internal/server.(*Server).cmdGET(0xc000004300, 0xc
0003140a0)

Operating System (please complete the following information):

  • OS: MacOS
  • CPU: amd64
  • Version: 1.19.0
  • Container: None

Additional context
Draft creating the panic in geojson tidwall/geojson#26

@tidwall
Copy link
Owner

tidwall commented Dec 18, 2023

That geometry is invalid. All points in a geometry should have the same number of coordinates.

I pushed a fix to the master branch which will return "invalid coordinates" when trying to SET the geometry

@prathik
Copy link
Author

prathik commented Dec 19, 2023

@tidwall - thanks! according to geojson spec it's a valid one though (validated with various linters). However, this fix works as well, I'd recommend responding with "invalid coordinates must provide z coordinate for all polygons" or something as such.

@prathik prathik closed this as completed Dec 19, 2023
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

No branches or pull requests

2 participants