paulmach / orb

Types and utilities for working with 2d geometry in Golang
MIT License
886 stars 103 forks source link

panic in wkt.Unmarshal #110

Closed sosiska closed 1 year ago

sosiska commented 1 year ago

Hello! I found a panic in the wkt.Unmarshal function.

Problem Panic occurs when using the wkt.Unmarshal function from orb/encoding/wkt package.

How to reproduce

package main

import (
    "fmt"
    "os"

    "github.com/paulmach/orb/encoding/wkt"
)

func main() {
    input := "LINESTRING"
    geom, err := wkt.Unmarshal(input)
    if err != nil {
        fmt.Printf("can't unmarshal: %v\n", err)
        os.Exit(0)
    }
    fmt.Printf("unmarshaled geom: %v\n", geom)
}

Expected behavior I expect to get something like an invalid format error, or at least a panic with a message, like:

can't unmarshal: incorrect WKT format

Current behavior

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

goroutine 1 [running]:
github.com/paulmach/orb/encoding/wkt.trimSpaceBrackets({0x0?, 0xa?})
        /home/kirill/go/pkg/mod/github.com/paulmach/orb@v0.7.1/encoding/wkt/unmarshal.go:125 +0x9c
github.com/paulmach/orb/encoding/wkt.Unmarshal({0x4a26bf?, 0x53a780?})
        /home/kirill/go/pkg/mod/github.com/paulmach/orb@v0.7.1/encoding/wkt/unmarshal.go:256 +0x4df
main.main()
        /home/kirill/go/src/github.com/sosiska/wkt/main.go:12 +0x29

Process finished with the exit code 2