Article View: linux.debian.bugs.dist
Article #4456Bug#1153953: tilemaker: allocator race crashes in 3.0.0-1 in trixie/stable
From: Florian Lohoff
Date: Sat, 14 Nov 2026 08:30
Date: Sat, 14 Nov 2026 08:30
158 lines
7657 bytes
7657 bytes
--Ty6EhoN8Js7ptVKO
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
Package: tilemaker
Version: 3.0.0-1
Tags: patch
Hi,
First ... thanks for maintaining tilemaker in Debian ..
I am running tilemaker in a Debian/Trixie based Docker container i built=20
myself every 30 minutes on a pretty small input. I saw occasional crashes of
tilemaker (Every 2-3 days)
I added instrumentation to push the coredump to safe store when it
happened.
With the help of sonnet i found at least 2 allocator races in tilemaker=20
3.0.0-1 - At least the first one is fixed in current git upstream=20
although the code has changed completely.
As these present crashes i though i at least document a way around in=20
the Debian bug tracker for Debian/Trixie e.g. stable for others
who trigger this.
I locally rebuilt the package for the Docker container with these two=20
patches:
This is the first race i found which is also fixed in upstream git.
Description: Lock region mutex when freeing from the thread's own mmap regi=
on
destroy() skipped the region mutex for the calling thread's own region,
racing with other threads freeing into it (e.g. BinarySearchNodeStore
deque growth). This corrupts the allocator state and can crash.
Forwarded: no
--- a/src/mmap_allocator.cpp
+++ b/src/mmap_allocator.cpp
@@ -223,6 +223,7 @@
if(mmap_shm_thread_region_ptr !=3D nullptr) {=09
auto &i =3D *mmap_shm_thread_region_ptr;
if(p >=3D (void const *)i.region.data() && p < reinterpret_cast<void c=
onst *>(reinterpret_cast<uint8_t const *>(i.region.data()) + i.region.size(=
))) {
+ std::lock_guard<std::mutex> lock(i.mutex);
allocator_t allocator(i.buffer.get_segment_manager());
return allocator.destroy(reinterpret_cast<uint8_t *>(p));
}
@@ -231,6 +232,7 @@
if(mmap_file_thread_ptr !=3D nullptr) {=09
auto &i =3D *mmap_file_thread_ptr;
if(p >=3D i.region.get_address() && p < reinterpret_cast<void const *>=
(reinterpret_cast<uint8_t const *>(i.region.get_address()) + i.region.get_s=
ize())) {
+ std::lock_guard<std::mutex> lock(i.mutex);
allocator_t allocator(i.buffer.get_segment_manager());
allocator.destroy(reinterpret_cast<uint8_t *>(p));
return;
The second crash and fix i found was this - Its still in upstream=20
tilemaker although the code changed significantly and the race is more
unlikely as upstream changed to std::dequeue - This solution
allocates a static array of 2**24 pointers - This only increases VSZ
when not touching them. Advantage is that no locking on read is
necessary which is missing in 3.0.0-1 and in upstream.
Description: Fix data race on PooledString table vector
tables[tableIndex] was read without a lock while another thread
push_back()ed (reallocating), yielding a garbage pointer in memcpy.
Use a fixed, never-reallocated table instead.
.
Crash (SIGSEGV, tilemaker 3.0.0-1, --input grid.pbf):
.
#0 libc memcpy (vmovdqu %xmm0,(%rdi)), rdi=3D0x7f6cab91b (garbage)
#1 memcpy (string_fortified.h:29)
#2 PooledString::PooledString(str=3D"L 747 Langenstrasse")
pooled_string.cpp:54 memcpy(tables[tableIndex] + offset, ...)
#3 PooledString::ensureStringIsOwned() pooled_string.cpp:159
#4 AttributePair::ensureStringIsOwned() attribute_store.cpp:65
#5 AttributePairStore::addPair() attribute_store.cpp:181
#6 AttributeStore::addAttribute(key=3D"name") attribute_store.cpp:247
#7 OsmLuaProcessing::Attribute() osm_lua_processing.cpp:831
#8 Lua Attribute() binding (kaguya) osm_lua_processing.cpp:215
#9.. kaguya invoke, liblua5.4, lua_pcallk
.
In the core, tableIndex=3D0 and tables had size 2 =3D=3D capacity 2 (just
grown by another thread), so the unlocked read of tables[0] hit the
freed old buffer.
Forwarded: no
--- a/src/pooled_string.cpp
+++ b/src/pooled_string.cpp
@@ -2,9 +2,13 @@
#include <stdexcept>
#include <mutex>
#include <cstring>
+#include <cstdlib>
=20
namespace PooledStringNS {
- std::vector<char*> tables;
+ // Fixed table (never reallocates); lazily committed by the OS.
+ const size_t MaxTables =3D 1 << 24;
+ char** const tables =3D (char**)calloc(MaxTables, sizeof(char*));
+ size_t numTables =3D 0;
std::mutex mutex;
=20
const uint8_t ShortString =3D 0b00;
@@ -35,8 +39,10 @@
char* buffer =3D (char*)malloc(spaceLeft);
if (buffer =3D=3D 0)
throw std::runtime_error("PooledString could not malloc");
- tables.push_back(buffer);
- tableIndex =3D tables.size() - 1;
+ if (numTables >=3D MaxTables)
+ throw std::runtime_error("PooledString out of tables");
+ tables[numTables] =3D buffer;
+ tableIndex =3D numTables++;
}
=20
storage[1] =3D tableIndex >> 16;
Flo
--=20
Florian Lohoff f@zz.de
Any sufficiently advanced technology is indistinguishable from magic.
--Ty6EhoN8Js7ptVKO
Content-Type: application/pgp-signature; name="signature.asc"
-----BEGIN PGP SIGNATURE-----
iQIzBAABCgAdFiEEdb9o7oebX2papQ/KkN1BIMsJ8i8FAmr4FaYACgkQkN1BIMsJ
8i/Bdw/8DZNqZs04e71Pn5TtUIVbhyLpf9d+7AwNzShMutqZ9GEl8KKHlPPeo8Qd
b14UFang9ijCAQ4ij0QoFIzNHWql6WSY7zs5fj72XKSVm5qbZDlamFqHE17+x/Gy
C2flFj0AkVnkHvZV7IScSh7C7vysMA/Ay6NrFgy2PUdq9BQPr7J3FD8ZX+VBxO91
q3L3dQTP4oOM3zUkyV1l5bJ2qzCFzXE5eLOw6fTb0hsGOyjI2axFZvRWTy09kP4F
kJLa/GUO6Xj9rOKtc+QdKmM4LSGRZZA/muqdVA/7Xs3thFbcYEcDupb2V8GqCgQo
y1peIZ94wyrpDaUSM7heaHZCwUqSwWE0KZdWrukjpPKy2vJa1Pt1ZAMto0TMel8d
iQ0GxAvNhkYNrdRyT+7AoS930mWxKTJn2tydCmACDWtZWczQ6qRAitZQs2ihM1vM
Am47RjNdEjfc6NCldTux+w0EzDsBaJ8iymJ55D2leT12uenZm4NI8JJJeQXh8D0s
j691WMc9LgD/kMMgFmZSW0RB2uNvopVipb8zivFKvEafoBnPr8VN1J6BGLjm3u1r
i9t55z/O6x0s3XD0aDnoG6wSH3Xvj3jrhh9JHdlJkLfzQO9BnHFciR76amVWbssD
OPSRLDrzZz3/7Sm6srQ0yuHocCjqck0USRWPTdxHF27gxLcEhvk=
=uL/H
-----END PGP SIGNATURE-----
--Ty6EhoN8Js7ptVKO--
Technical Details
Message-ID:
<NZhj3-bNLb-9@gated-at.bofh.it>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.corradoroberto.it!diesel.cu.mi.it!bofh.it!news.nic.it!robomodShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.corradoroberto.it!diesel.cu.mi.it!bofh.it!news.nic.it!robomod From: Florian Lohoff <f@zz.de> Newsgroups: linux.debian.bugs.dist Subject: Bug#1153953: tilemaker: allocator race crashes in 3.0.0-1 in trixie/stable Date: Sat, 14 Nov 2026 09:30:01 +0100 Message-ID: <NZhj3-bNLb-9@gated-at.bofh.it> X-Original-To: submit@bugs.debian.org X-Mailbox-Line: From debian-bugs-dist-request@lists.debian.org Sat Nov 14 08:25:12 2026 Old-Return-Path: <debbugs@buxtehude.debian.org> X-Spam-Flag: NO X-Spam-Score: -1.45 Reply-To: Florian Lohoff <f@zz.de>, 1153953@bugs.debian.org Resent-To: debian-bugs-dist@lists.debian.org Resent-Cc: pkg-grass-devel@lists.alioth.debian.org X-Debian-Pr-Message: report 1153953 X-Debian-Pr-Package: tilemaker X-Debian-Pr-Keywords: patch X-Debian-Pr-Source: tilemaker MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="Ty6EhoN8Js7ptVKO" Content-Disposition: inline Organization: rfc822 - pure communication X-Ms-Reactions: disallow X-Greylist: delayed 1158 seconds by postgrey-1.37 at buxtehude; Sat, 14 Nov 2026 08:22:23 UTC X-Debian-Message: from BTS X-Mailing-List: <debian-bugs-dist@lists.debian.org> archive/latest/2002515 List-ID: <debian-bugs-dist.lists.debian.org> List-URL: <https://lists.debian.org/debian-bugs-dist/> Approved: robomod@news.nic.it Lines: 158 Sender: robomod@news.nic.it X-Original-Date: Sat, 14 Nov 2026 09:02:48 +0100 X-Original-Message-ID: <avgVqBZ6fVPc8PPP@pax.zz.de>