Opened 6 years ago

Closed 6 years ago

#4109 closed defect (fixed)

WKT parser accepting and interpreting numbers with multiple dots

Reported by: strk Owned by: pramsey
Priority: medium Milestone: PostGIS 2.5.0
Component: postgis Version: master
Keywords: Cc:

Description

I think the following query should raise an exception rather than giving a debatable interpretation:

select ST_AsEWKT('LINESTRING(1.1.1, 2.2.2)'::geometry);
LINESTRING(1.1 0.1,2.2 0.2)

Not sure how back this bug goes

Change History (3)

comment:1 by pramsey, 6 years ago

Probably all the way back to the beginning, or at least to the introduction of flex, I think, as I'd guess it's an issue with the lexer.

comment:2 by Algunenano, 6 years ago

Seems like the issue comes from ignoring WHITESPACEs in the coordinate declaration and supporting numbers as .5 (0.5):

# select ST_AsEWKT('LINESTRING(.1 .2, .3 .4)'::geometry);
          st_asewkt          
-----------------------------
 LINESTRING(0.1 0.2,0.3 0.4)
(1 row)

# select ST_AsEWKT('LINESTRING(.1.2, .3.4)'::geometry);
          st_asewkt          
-----------------------------
 LINESTRING(0.1 0.2,0.3 0.4)
(1 row)

This probably goes back to 2010.

I've given it a try in https://github.com/postgis/postgis/pull/277

After the change:

ERROR:  parse error - invalid geometry
LINE 1: select ST_AsEWKT('LINESTRING(.1.2, .3.4)'::geometry);
                         ^
HINT:  "LINESTRING(.1.2," <-- parse error at position 16 within geometry

The main problem is that some other matching rules had to be modified to now accept optional whitespaces before or after the main string. It'd nice if someone with experience with Bison (or other parsers) could have a look to see how it can be improved, and also because I've relied on the tests to check if anything was broken.

comment:3 by Raul Marin, 6 years ago

Resolution: fixed
Status: newclosed

In 16662:

Fix WKT parser accepting numbers with multiple dots

Closes #4109
Closes https://github.com/postgis/postgis/pull/277

Note: See TracTickets for help on using tickets.