Skip to content

lib/raster: Fix crash when writing rasters with 268,435,455 or more rows - #8320

Open
Valyrian-Code wants to merge 2 commits into
OSGeo:mainfrom
Valyrian-Code:lib-raster-rowptr-size
Open

Valyrian-Code wants to merge 2 commits into
OSGeo:mainfrom
Valyrian-Code:lib-raster-rowptr-size

Conversation

@Valyrian-Code

@Valyrian-Code Valyrian-Code commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #8317.

G_zero() takes an int size and crashed on the row pointer tables from 268,435,455 rows. G_calloc() already zeroes them, so those calls are removed.

The table sizes in format.c are now size_t, and the table is read and written in pieces of at most INT_MAX bytes, the macOS limit per call.

Tested on macOS: maps of 268,435,455 and 536,870,912 rows write and read back correctly, and small maps are byte-identical to main. No CI test, since it needs a 2 GB row table.

Copilot AI balanced review requested due to automatic review settings December 4, 2026 21:00

This comment was marked as low quality.

@wenzeslaus

Copy link
Copy Markdown
Member

Can you check the performance of it? I would hope the loops are somehow rolled out, but without numbers, it does not look good adding loops to this place. Also, it is more code then I hoped, but that's not a surprise.

@Valyrian-Code

Copy link
Copy Markdown
Contributor Author

Can you check the performance of it? I would hope the loops are somehow rolled out, but without numbers, it does not look good adding loops to this place. Also, it is more code then I hoped, but that's not a surprise.

I timed main vs this PR and see no difference beyond noise, on macOS and Linux.

The loop runs once per call unless the table is over INT_MAX bytes.
It's there because on Linux one write() of the 268,435,455-row table is short.

Would you like me to keep it this way, or should I make it smaller and just stop with an error for tables that large?
or do you have anything else or any other direction in mind?

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 this pull request may close these issues.

lib/raster: Segfault when writing a raster with 268,435,455 or more rows

3 participants