@@ -201,16 +201,28 @@ static tile_extent get_extent_from_db(pg_conn_t const &db_connection,
201201}
202202
203203static std::vector<std::pair<uint32_t , uint32_t >>
204- get_tiles_from_table (pg_conn_t const &connection, std::string const &table)
204+ get_tiles_from_table (pg_conn_t const &connection, std::string const &table,
205+ uint32_t zoom)
205206{
206- std::vector<std::pair<uint32_t , uint32_t >> tiles;
207+ auto const result = connection.exec (
208+ R"( SELECT x, y FROM "{}" WHERE zoom = {})" , table, zoom);
207209
208- auto const result = connection.exec (R"( SELECT x, y FROM "{}")" , table);
210+ std::vector<std::pair<uint32_t , uint32_t >> tiles;
211+ tiles.reserve (result.num_tuples ());
209212
213+ uint32_t const max = 1UL << zoom;
210214 for (int n = 0 ; n < result.num_tuples (); ++n) {
211215 char *end = nullptr ;
212216 auto const x = std::strtoul (result.get_value (n, 0 ), &end, 10 );
217+ if (*end != ' \0 ' || x >= max) {
218+ log_error (" Ignoring invalid x value in expire table '{}'" , table);
219+ continue ;
220+ }
213221 auto const y = std::strtoul (result.get_value (n, 1 ), &end, 10 );
222+ if (*end != ' \0 ' || y >= max) {
223+ log_error (" Ignoring invalid y value in expire table '{}'" , table);
224+ continue ;
225+ }
214226 tiles.emplace_back (x, y);
215227 }
216228
@@ -497,7 +509,7 @@ class genproc_t
497509 auto const table = params.get_string (" expire_list" );
498510 log_debug (" Running generalizer for expire list from table '{}'..." ,
499511 table);
500- tile_list = get_tiles_from_table (db_connection, table);
512+ tile_list = get_tiles_from_table (db_connection, table, zoom );
501513 log_debug (" Truncating table '{}'..." , table);
502514 db_connection.exec (" TRUNCATE {}" , table);
503515 } else {
0 commit comments