[From nobody Sat Nov 14 11:09:05 2026
Received: (at submit) by bugs.debian.org; 14 Nov 2026 08:22:24 +0000
X-Spam-Checker-Version: SpamAssassin 4.0.1-bugs.debian.org_2005_01_02
 (2024-03-25) on buxtehude.debian.org
X-Spam-Level: 
X-Spam-Status: No, score=-15.2 required=4.0 tests=BAYES_00,DKIM_SIGNED,
 DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,HAS_PACKAGE,PGPSIGNATURE,
 SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no
 version=4.0.1-bugs.debian.org_2005_01_02
X-Spam-Bayes: score:0.0000 Tokens: new, 115; hammy, 150; neutral, 145; spammy,
 0. spammytokens: hammytokens:0.000-+--trixie,
 0.000-+--H*ct:application, 0.000-+--H*ct:protocol,
 0.000-+--H*ct:micalg, 0.000-+--H*ct:signed
Return-path: &lt;f@zz.de&gt;
Received: from pax.zz.de ([2a01:4f8:10b:e5e::2]:52274)
 by buxtehude.debian.org with esmtps
 (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256)
 (Exim 4.96) (envelope-from &lt;f@zz.de&gt;) id 1xS91k-008CAk-0B
 for submit@bugs.debian.org; Sat, 14 Nov 2026 08:22:24 +0000
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=zz.de; s=mail;
 t=1794643375; bh=dUWK5VFz0ugyLJh56/zzalmj9Ww7yFLqZ4J4hVJM3co=;
 h=Date:From:To:Subject:From;
 b=eJ2folSEuVtaG4cPev8OVkjtabjOQCXeGjwzez9L5boKy6ubQIOi5VBVXJA9sOkvY
 r9+trBGAFr5AdeTk5NbaJp/3ysXN3SSw4qOg4qc5cHqSrkgwl12UTKlnyT8OcGnK+q
 2IlRQyZp/yKp/t+UjSkMUjqJueHXELj+ivwH6kL+FycjlFbY7UL9H0VQSbNkS5nYM8
 oDqJXyDfj/BdRqeG7xAP9f6nRbr05bt2p7fG3nQNB2l+Re7lunv5Eqx28IStWyeAbs
 sGIWk+Q9xBQGujdsqqetO9d7Snn3BMo65PTrWo4eGaRE64shyNzQmMmTw4lDcnbbM9
 dNAeibcoqLkYw==
X-Virus-Scanned: Debian amavis at pax.zz.de
Received: by pax.zz.de (Postfix, from userid 1181)
 id 12E65120178; Sat, 14 Nov 2026 09:02:48 +0100 (CET)
Date: Sat, 14 Nov 2026 09:02:48 +0100
From: Florian Lohoff &lt;f@zz.de&gt;
To: submit@bugs.debian.org
Subject: tilemaker: allocator race crashes in 3.0.0-1 in trixie/stable
Message-ID: &lt;avgVqBZ6fVPc8PPP@pax.zz.de&gt;
MIME-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha512;
 protocol=&quot;application/pgp-signature&quot;; boundary=&quot;Ty6EhoN8Js7ptVKO&quot;
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
Delivered-To: submit@bugs.debian.org


--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 &amp;i =3D *mmap_shm_thread_region_ptr;
  		if(p &gt;=3D (void const *)i.region.data()  &amp;&amp; p &lt; reinterpret_cast&lt;void c=
onst *&gt;(reinterpret_cast&lt;uint8_t const *&gt;(i.region.data()) + i.region.size(=
))) {
+			std::lock_guard&lt;std::mutex&gt; lock(i.mutex);
  			allocator_t allocator(i.buffer.get_segment_manager());
  			return allocator.destroy(reinterpret_cast&lt;uint8_t *&gt;(p));
  		}
@@ -231,6 +232,7 @@
  	if(mmap_file_thread_ptr !=3D nullptr) {=09
  		auto &amp;i =3D *mmap_file_thread_ptr;
  		if(p &gt;=3D i.region.get_address()  &amp;&amp; p &lt; reinterpret_cast&lt;void const *&gt;=
(reinterpret_cast&lt;uint8_t const *&gt;(i.region.get_address()) + i.region.get_s=
ize())) {
+			std::lock_guard&lt;std::mutex&gt; lock(i.mutex);
  			allocator_t allocator(i.buffer.get_segment_manager());
  			allocator.destroy(reinterpret_cast&lt;uint8_t *&gt;(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&quot;L 747 Langenstrasse&quot;)
      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&quot;name&quot;) 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 &lt;stdexcept&gt;
  #include &lt;mutex&gt;
  #include &lt;cstring&gt;
+#include &lt;cstdlib&gt;
 =20
  namespace PooledStringNS {
-	std::vector&lt;char*&gt; tables;
+	// Fixed table (never reallocates); lazily committed by the OS.
+	const size_t MaxTables =3D 1 &lt;&lt; 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(&quot;PooledString could not malloc&quot;);
-			tables.push_back(buffer);
-			tableIndex =3D tables.size() - 1;
+			if (numTables &gt;=3D MaxTables)
+				throw std::runtime_error(&quot;PooledString out of tables&quot;);
+			tables[numTables] =3D buffer;
+			tableIndex =3D numTables++;
  		}
 =20
  		storage[1] =3D tableIndex &gt;&gt; 16;


Flo
--=20
Florian Lohoff                                                     f@zz.de
   Any sufficiently advanced technology is indistinguishable from magic.

--Ty6EhoN8Js7ptVKO
Content-Type: application/pgp-signature; name=&quot;signature.asc&quot;

-----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--
]