Skip to content

Casting a geometry column to LINESTRING_2D results in a malloc error, crashing duckdb #548

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

Closed
carstonhernke opened this issue Apr 21, 2025 · 4 comments · Fixed by #549
Closed

Comments

@carstonhernke
Copy link

Hi! I was working with some road centerline (line) data, attempting to convert it to the experimental LINESTRING_2D type and I came across some unexpected behavior.

Platform: MacOS Sonoma (running DuckDB from command line)
DuckDB version: 1.2.2
Spatial extension version: 3bb37f8

(I'm also seeing similar behavior in the Wasm build at shell.duckdb.org. Steps to reproduce are the same)

Data:
13838 rows, with a geometry column (geom_transformed) representing streets in Minneapolis, MN using the EPSG:4326 CRS.
File can be downloaded at https://github.com/carstonhernke/demo-h3-data/blob/main/parquet/mpls_streets.parquet

Steps to reproduce:

  1. load spatial;
  2. create table geo as select * from 'mpls_streets.parquet';
  3. select "geom_transformed"::LINESTRING_2D as line from geo;

At the last step, duckdb reliably crashes, with the following error message:

duckdb(36426,0x1f6e68f40) malloc: Incorrect checksum for freed object 0x12289dc00: probably modified after being freed.
Corrupt value: 0x404672fbd9844419
duckdb(36426,0x1f6e68f40) malloc: *** set a breakpoint in malloc_error_break to debug
zsh: abort      duckdb

I haven't been able to narrow the error down to a specific row. All of the rows contain a valid geometry, and none of them are especially complicated. Thanks in advance for the help!

@carstonhernke
Copy link
Author

Additional info:

I suspected that the high precision of the coordinates could be an issue, but I still see the issue when I use ST_ReducePrecision to truncate the coordinates:

  1. load spatial;
  2. create table geo as select * from 'mpls_streets.parquet';
  3. create table geo_simplified as select ST_ReducePrecision("geom_transformed", .0001) as line from geo;
  4. select line::LINESTRING_2D as line from geo_simplified;

@Maxxen Maxxen mentioned this issue Apr 22, 2025
@Maxxen Maxxen linked a pull request Apr 22, 2025 that will close this issue
@Maxxen
Copy link
Member

Maxxen commented Apr 22, 2025

Hello! Thanks for reporting! This turned out to be caused by a pointer lifetime issue, fixed in the above linked PR.

@Maxxen Maxxen closed this as completed Apr 22, 2025
@carstonhernke
Copy link
Author

Great, thanks for the quick fix @Maxxen !!

@carstonhernke
Copy link
Author

Just tested the recent build, works!

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 a pull request may close this issue.

2 participants