Opened 13 months ago

Closed 13 months ago

Last modified 9 months ago

#3997 closed defect (fixed)

Division by zero in iterate_4d

Reported by: Algunenano Owned by: strk
Priority: medium Milestone: PostGIS 2.5.0
Component: liblwgeom Version: trunk
Keywords: Cc:

Description

There is a typo calculating distances in the z-axis.

It appeared as an error as a division by zero

lwgeom_median.c:111:17: runtime error: division by zero

in the test

do_median_test("MULTIPOINT ZM ((0 -1 0 1), (0 0 0 1), (0 1 0 0.5), (0 1 0 0.5))", "POINT (0 0 0)", LW_TRUE, 1000);

Github PR: https://github.com/postgis/postgis/pull/196

Change History (9)

comment:1 Changed 13 months ago by komzpa

Resolution: fixed
Status: newclosed

In 16341:

Fix bug in iterate_4d.

Patch by Raúl Marín Rodríguez.

Closes #3997
Closes https://github.com/postgis/postgis/pull/196

comment:2 Changed 13 months ago by strk

Resolution: fixed
Status: closedreopened

Such fixes should come with a testcase. Can you please add one Raul? Or Komzpa ?

comment:3 Changed 13 months ago by Algunenano

Working on it. It's really tricky you need a really specific geometry. Also the division by zero is still possible.

comment:4 Changed 13 months ago by Algunenano

PR with the test and removing the possibility of division by zero: https://github.com/postgis/postgis/pull/198

comment:5 Changed 13 months ago by pramsey

Resolution: fixed
Status: reopenedclosed

In 16366:

lwgeom_median: Avoid division by zero
(Raúl Marín Rodríguez)
Closes #3997
Closes https://github.com/postgis/postgis/pull/198

comment:6 Changed 13 months ago by Algunenano

Resolution: fixed
Status: closedreopened

As @komzpa commented in the GH issue (https://github.com/postgis/postgis/pull/198#issuecomment-362911760) the ticket introduced here is failing.

Here is the PR with the fix (basically change how the check is done, from comparing coordinates to comparing sum of distances): https://github.com/postgis/postgis/pull/205

comment:7 Changed 13 months ago by Algunenano

Resolution: fixed
Status: reopenedclosed

comment:8 Changed 9 months ago by Raul Marin

In 16579:

Fix bug in lwgeom_median and avoid division by zero

References #3997
Closes https://github.com/postgis/postgis/pull/244

comment:9 Changed 9 months ago by Raul Marin

In 16580:

Fix bug in lwgeom_median and avoid division by zero

References #3997
Closes https://github.com/postgis/postgis/pull/245

Note: See TracTickets for help on using tickets.