1
0
mirror of https://github.com/MariaDB/server.git synced 2026-10-23 18:49:29 +03:00

222 Commits

Author SHA1 Message Date
Oleksandr Byelkin
f860f2a937 Merge branch '11.8' into 12.3 2026-08-20 08:27:14 +02:00
Oleksandr Byelkin
3b8db45403 Merge branch '11.4' into 11.8 2026-08-19 11:28:01 +02:00
Oleksandr Byelkin
e2b15641ec Merge branch '10.6' into 10.11 2026-08-19 08:13:54 +02:00
Daniel Black
51263b851d MDEV-39813 ST_GeomFromGeoJSON does not control recursion depth
Using stack_p wasn't a portable concept in 12.3 when JSON
parsing got unlimited depth. To let ST_GeomFromGeoJSON was
already a recursive function, needed because object order of "type"
may be after the "geometries", but with json_engine_t no longer
enforcing the depth, some stack checking was required.

Use the check_stack_depth function to allow excessively deep
GeoJSON objects to error.

As this is cleaned up the gis-json test can be enabled.

The exceeding stack depth is moved to lotofstack.test.
2026-08-01 10:34:23 +10:00
Akshat Nehra
d0eb9e167a MDEV-39981 Fix ST_GEOMFROMGEOJSON returning wrong result with reversed key order
ST_GEOMFROMGEOJSON requires JSON keys to appear in a specific order
(type before geometries/features/geometry/coordinates). When keys
appear in a different order, the JSON scanner is left in an
inconsistent state because json_skip_level() is not called to advance
past the value when the type has not yet been determined.

Fix: add json_skip_level() calls in the geometries, features, and
geometry key handlers when the type key has not yet been encountered.
This mirrors the existing pattern in the coordinates handler.

All new code of the whole pull request, including one or several files
that are either new files or modified ones, are contributed under the
BSD-new license. I am contributing on behalf of my employer Amazon Web
Services, Inc.
2026-07-31 08:22:14 +02:00
Daniel Black
e4bdf5596c MDEV-39813 ST_GeomFromGeoJSON does not control recursion depth
Geometry::create_from_json used strings as things that reinitialize
the je (json_engine). By reinitializing with json_start the killed
pointer gets reset, and also the concept of depth is reset.

There are two states in create_from_json:
1. The search if for the type, once found ci is set
2. Search for the argument, arg becomes != T_NONE

If the type is found first, ci become the class, and once
the arg is found, continued execution on the same je occurs.

If the argument comes before the "type", we've save a copy
of the json_engine_t to process this argument.

In both cases je after the execution is the most progressed
pointer.

Debug assertions on je state aren't enforced by code, if
some invalid GeoJSON is passed, these are actual errors.

Because Geometry::create_from_json is recursive, from
geometrymcollections, a json_read_value is pushed from inside this
function up to Item_func_geometry_from_json::val_str.

Other Gis*::init_from_json start from their actual object and don't
need a json_read_value to start.

Test case an bug report thanks to byteoverride.
2026-07-31 08:22:14 +02:00
forkfun
33240f3c96 Merge branch '11.8' into '12.3' 2026-07-30 11:41:55 +02:00
Daniel Black
97967e7882 MDEV-40552 UBSAN: not a valid value for wkbByteOrder Gis_multi_point
The byteorder field could contain an invalid value (> 1) on a GIS
multi_point object where there byteorder was on any of the inner points.

This can occur with any of the GIS "*FromWKB" functions that contained
a multipoint object.

This result in a invalid object being accepted and also potentially
trigger undefined behaviour in the processing of the object.
2026-07-30 17:49:03 +10:00
forkfun
eaca80bf32 Merge branch '11.4' into '11.8' 2026-07-29 12:27:46 +02:00
Sergei Golubchik
8856f9fe19 MDEV-40540 ST_GeomFromWKB stack overrun on deeply nested GeometryCollection 2026-07-28 18:36:12 +02:00
forkfun
ad7f29afb3 Merge branch 10.6 into 10.11 2026-07-23 11:12:27 +02:00
Sergei Golubchik
f221495d59 MDEV-40409 ST_GeomFromText stack overrun on deeply nested GeometryCollection 2026-07-22 13:22:04 +02:00
Sergei Golubchik
5c04ca5524 MDEV-40329 Binary_string::qs_append(char): Assertion `str_length + (uint32) (1) <= Alloced_length' failed in AsText
Geometry::as_wkt() didn't take into account bytes written into the
result string in the recusrive call of get_data_as_wkt().
Gis_geometry_collection::get_data_as_wkt() didn't reserve space at all.
Thus nested geometry collections could overflow the buffer.
2026-07-22 13:22:03 +02:00
Sergei Golubchik
2bf355e361 MDEV-40328 ASAN error on malformed WKB multipolygon
before `data+= WKB_HEADER_SIZE` verify that there's enough data.

rewrite this line in Gis_multi_line_string::get_mbr to make clear
that it does not need this check.
2026-07-22 13:22:03 +02:00
Dave Gosselin
89c4d2f00c MDEV-38669: ASAN fail in Item_func_collect::add during ST_COLLECT
st_collect read past the end of its input because it assumed
that the input was a valid geometry.  Check that the length of the
input is at least long enough to possibly contain a valid geometry.
2026-07-19 16:35:20 +10:00
Daniel Black
1dd7b96429 MDEV-26813 UBSAN: bool wkbByteOrder via Geometry::wkbByteOrder (multi_line_string)
Parsing a wkb of a multi_line_string needs to validate the
wkbByteOrder field for <= wkb_ndr to be valid, otherwise
return null.

Note that wkb[0] is a char, so can be signed, hence the cast and
> 0x80 values in the test case.
2026-07-17 07:46:30 +10:00
Daniel Black
46b2f83702 MDEV-35595 UBSAN: runtime error: load of value 3 for wkbByteOrder
When creating Geometry objects from raw bytes, validate the byte order
is not > wkb_ndr, a constant for little endian being the upper bound of
the wkbByteOrder.

The 3 validation locations are the callers to the other init_from_wkb
functions for other geometry types, which prevent an invalid value from
reaching wkb_get_uint. As wkb[0], a char can signed, use uchar for
comparision. The other value in the wkb_ndr enum is wkb_xdr being 0
which makes > wk_ndr a valid test of the two allowed values.
2026-07-17 07:46:30 +10:00
Dave Gosselin
2ff230f5fa MDEV-39911: Crash in ST_SIMPLIFY of a collection geometry
ST_SIMPLIFY of a multilinestring, polygon, multipolygon, or geometry
collection reserved space for the result header but omitted the four
byte element count that it then appends.  This resulted in a buffer
overrun.

Reserve the full header size, including the count, in each of the four
collection simplify functions, the same fix applied for MDEV-35062 and
MDEV-36042.
2026-07-06 10:35:42 -04:00
Marko Mäkelä
3adf432a9f Merge 11.8 into 12.3 2026-06-29 07:40:04 +03:00
Marko Mäkelä
761c2333ca Merge 11.4 into 11.8 2026-06-26 13:46:45 +03:00
Daniel Black
f249b0196d Merge 10.6 into 10.11 2026-06-26 17:56:20 +10:00
Daniel Black
fda9d85c06 MDEV-39813 ST_GeomFromGeoJSON does not control recursion depth
Geometry::create_from_json reset the killedptr and the stack
depth (stack_p) every time json_scan_start was called. We save/
restore these values so that the ST_GeomFrom_GeoJSON can be killed
and incur timeout, and also so that its depth measurement is kept.

Test case an bug report thanks to byteoverride.
2026-06-26 07:32:21 +03:00
forkfun
867d16cea7 Merge branch '11.4' into '11.8' 2026-06-23 12:52:39 +02:00
Oleksandr Byelkin
0d59c434fa Merge branch '10.6' into 10.11 2026-06-21 15:32:20 +02:00
Dave Gosselin
115e5e83b7 MDEV-36891: std::make_pair compiler note
Construct the pair in place with emplace_back to silence the build
note.
2026-06-10 15:35:49 +10:00
Oleksandr Byelkin
9f98f82b14 Merge branch '11.8' into 12.3 2026-05-26 21:15:58 +02:00
Sergei Golubchik
6b35f1748d Merge branch '11.4' into 11.8 2026-05-23 21:43:50 +02:00
Sergei Golubchik
197f92bee0 Merge branch '10.6' into 10.11 2026-05-23 16:55:50 +02:00
Sergei Golubchik
32ab8a2d4c MDEV-39657 ASAN error on malformed WKB point
check data length for Gis_point
2026-05-20 22:49:20 +02:00
Oleksandr Byelkin
9cb70f0220 Merge branch '11.4' into 11.8 2026-05-08 08:11:03 +02:00
Oleksandr Byelkin
6828ff7390 Merge branch '10.6' into 10.11 2026-05-08 07:38:22 +02:00
Sergei Golubchik
d0501281ec MDEV-39481 ASAN error on malformed WKB polygon
let's make is difficult for wkb and len to desync
2026-05-06 13:28:23 +02:00
Daniel Black
b74f39db60 MDEV-35545 UBSAN Gis_geometry_collection::init_from_opresult
From the UBSAN error:

sql/spatial.cc:3364:10: runtime error: applying non-zero offset 1 to null pointer

In Gis_geometry_collection::init_from_opresult, a pointer argument
was being treated as a counter for the Special case of
GEOMETRYCOLLECTION EMPTY. The memory location was never accessed.

Rather than use points to count and return a difference at the end, the
code is replace to use g_len_total as a counter. This gets a 1 value for
the GEOMETRYCOLLECTION EMPTY case and no ointer undefined behaviours
occur.

As other init_from_opresult functions return uint both g_len and
result use that type.
2026-05-05 10:27:15 +10:00
Sergei Golubchik
7984408bbd MDEV-39481 ASAN error on malformed WKB polygon 2026-04-29 15:38:03 +02:00
Marko Mäkelä
58f507206f Merge 10.6 into 10.11 2026-04-20 11:07:30 +03:00
Yuchen Pei
3a7f7ce521 Merge branch '11.4' into 11.8 2026-04-20 13:16:55 +10:00
Sergei Golubchik
f81c247f97 MDEV-39279 ASAN error on malformed WKB
Discovered by Riley Scott Jacob
2026-04-12 18:07:59 +02:00
Abhishek Bansal
ddd28da85f MDEV-34079: ST_AsGeoJSON returns incorrect value for empty geometry
ST_AsGeoJSON stripped the first '[' bracket when serializing an EMPTY
GeometryCollection, outputting '{"type": "GeometryCollection",
"geometries":]}'.

This occurred because several Gis_*::get_data_as_json functions
unconditionally truncated the last 2 characters of their String buffer
to remove the trailing ', ' appended inside their element loops. For
empty collections, the loop doesn't execute and there is no trailing
comma, causing the truncate to strip the initial '[' bracket.

Fixed by checking if the last character in the buffer is ' ' before
truncating.
2026-04-02 10:43:36 +03:00
Monty
038a05ab4d Fixed compiler warnings about using unitialized variables 2025-09-30 17:37:11 +03:00
Dave Gosselin
48a20c737f Fix MSAN failures in main.gis and main.spatial_utility_function_validate 2025-04-22 16:26:36 -04:00
Dave Gosselin
db49003660 Initialize pointers to avoid MSAN warnings 2025-04-22 16:26:36 -04:00
Dave Gosselin
53f82a9c3d MDEV-36042 Assertion failed in Binary_string::q_append
Like MDEV-35062, reserve sufficient space in the result for
q_append'ed data, as q_append does not itself reserve space like
it's append counterpart.
2025-04-22 16:26:36 -04:00
Alexey Botchkov
4b720b027d MDEV-35126 Wrong results from st_isvalid for multipolygon.
The Gis_polygon::is_valid() and the Gis_multi_polygon::is_valid()
  implemented with precise geometry engine.
2025-04-22 16:26:36 -04:00
Dave Gosselin
8c2a207d58 MDEV-35062 Assertion failed in Binary_string::q_append
Reserve sufficient space in the result for q_append'ed data, as
q_append does not itself reserve space like it's append counterpart.
2025-04-22 16:26:36 -04:00
Stefano Petrilli
b50366667b MDEV-34137: Implement the GIS function ST_Validate
The GIS function ST_Validate takes ad input a geometry and verifies that
- is compliant with the Well-Known Binary (WKB) format and Spatial
  Reference System Identifier (SRID) syntax.
- is geometrically valid.
If the input is valid return it, else it returns NULL. The use case of
this function is to filter out invalid geometry data.

Author: StefanoPetrilli <stefanop_1999@hotmail.it>
Co-authored-by: Torje Digernes <torje.digernes@oracle.com>
Co-authored-by: Hans H Melby <hans.h.melby@oracle.com>
Co-authored-by: Jon Olav Hauglid <jon.hauglid@oracle.com>
Co-authored-by: Erlend Dahl <erlend.dahl@oracle.com>
Co-authored-by: Norvald H. Ryeng <norvald.ryeng@oracle.com>
Co-authored-by: David.Zhao <david.zhao@oracle.com>
Co-authored-by: Pavan <pavan.naik@oracle.com>
2025-04-22 16:26:36 -04:00
Stefano Petrilli
ba66f8f37b MDEV-34141: Implements the function ST_Simplify
The GIS function ST_Simplify takes ad input a geometry and a double. It
applies the Ramer-Douglas-Peucker algorithm on the geometry and returns
the resulting geometry. The tests have been cherry-picked from the MySQL
implementation of this function to grant compatibility among the two
implementations.

Co-authored-by: David Zhao <david.zhao@oracle.com>
Co-authored-by: Pavan Naik <pavan.naik@oracle.com>
Co-authored-by: Norvald H. Ryeng <norvald.ryeng@oracle.com>
Co-authored-by: Erlend Dahl <erlend.dahl@oracle.com>
Co-authored-by: Jon Hauglid <jon.hauglid@oracle.com>
Co-authored-by: Hans H Melby <hans.h.melby@oracle.com>
Co-authored-by: Tor Didriksen <tor.didriksen@oracle.com>
2025-04-22 16:26:36 -04:00
StefanoPetrilli
1656b5c10f MDEV-34276: Implements the function ST_IsValid
The GIS function ST_Simplify takes ad input a geometry and returns 1
if the argument is geometrically valid, 0 if the argument is not
geometrically valid.

Author: StefanoPetrilli <stefanop_1999@hotmail.it>
Co-authored-by: Ahmed Ibrahim <ahmed.ibr.hashim@gmail.com>
Co-authored-by: Jon Olav Hauglid <jon.hauglid@oracle.com>
Co-authored-by: Erlend Dahl <erlend.dahl@oracle.com>
Co-authored-by: Norvald H. Ryeng <norvald.ryeng@oracle.com>
Co-authored-by: Menelaos Karavelas <menelaos.karavelas@oracle.com>
Co-authored-by: David.Zhao <david.zhao@oracle.com>
Co-authored-by: Pavan <pavan.naik@oracle.com>
2025-04-22 16:26:36 -04:00
StefanoPetrilli
1401d2fcd0 MDEV-34138: Implements the function MBRCoveredBy
Returns 1 or 0 to indicate whether the minimum bounding rectangle of g1
is covered by the minimum bounding rectangle of g2. The tests have been
cherry-picked from the MySQL implementation of this function to grant
compatibility among the two implementations.

Co-authored-by: Erlend Dahl <erlend.dahl@oracle.com>
Co-authored-by: Norvald H. Ryeng <norvald.ryeng@oracle.com>
Co-authored-by: Martin Hansson  <martin.hansson@oracle.com>
Co-authored-by: Erik Froseth <erik.froseth@oracle.com>
Co-authored-by: Hans H Melby <hans.h.melby@oracle.com>
Co-authored-by: Jens Even Berg Blomsøy <jens.even.blomosoy@oracle.com>
Co-authored-by: David Zhao <david.zhao@oracle.com>
Co-authored-by: BennyWang <benny.wang@oracle.com>
2025-04-22 16:26:36 -04:00
Vasilii Lakhin
717c12de0e Fix typos in C comments inside sql/ 2025-03-14 12:08:56 +04:00
Sergei Golubchik
32e6f8ff2e cleanup: remove unconditional #ifdef's 2024-11-05 14:00:47 -08:00