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

194 Commits

Author SHA1 Message Date
Oleksandr Byelkin
e2b15641ec Merge branch '10.6' into 10.11 2026-08-19 08:13:54 +02: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
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
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
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
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
Oleksandr Byelkin
0d59c434fa Merge branch '10.6' into 10.11 2026-06-21 15:32:20 +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
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
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
Marko Mäkelä
a8a5c8a1b8 Merge 10.5 into 10.6 2022-12-13 16:58:58 +02:00
Marko Mäkelä
1dc2f35598 Merge 10.4 into 10.5 2022-12-13 14:39:18 +02:00
Daniel Black
8f3631d009 MDEV-30150 ST_GeomFromGeoJSON, 'geometry' before 'type: feature' error
The geometry type requires Type:"Feature" but the feature need
not be first in the JSON structure.

Adjust code to return an error if geometry isn't a JSON object,
but continue parsing searching for Type: "Feature" to trigger
the geometry parsing.

Thanks Derick Magnusen for the bug report.
2022-12-09 08:49:43 +11:00
Oleksandr Byelkin
e5aa58190f Merge branch '10.5' into 10.6 2022-11-02 14:33:20 +01:00
Oleksandr Byelkin
4519b42e61 Merge branch '10.4' into 10.5 2022-10-26 15:26:06 +02:00
Alexey Botchkov
77951dd710 MDEV-26161 crash in Gis_point::calculate_haversine
More checks for bad geometry data added.
2022-10-26 00:20:40 +04:00
Sergei Golubchik
e910dff81e MDEV-26161 crash in Gis_point::calculate_haversine
return an error on invalid gis data
2022-10-25 21:26:51 +02:00
Marko Mäkelä
0ad8a825a8 Merge 10.5 into 10.6 2021-07-02 17:00:05 +03:00
Marko Mäkelä
15dcb8bd3e Merge 10.4 into 10.5 2021-07-02 13:02:26 +03:00
Sergei Petrunia
586870f9ef Merge 10.2->10.3 2021-06-30 15:06:54 +03:00
Alexey Botchkov
8147d2e618 MDEV-25461 Assertion `je->state == JST_KEY' failed in Geometry::create_from_json.
Handle invalid GEOJSON-s in Geometry::create_from_json().
2021-06-28 11:53:33 +04:00
Monty
b6ff139aa3 Reduce usage of strlen()
Changes:
- To detect automatic strlen() I removed the methods in String that
  uses 'const char *' without a length:
  - String::append(const char*)
  - Binary_string(const char *str)
  - String(const char *str, CHARSET_INFO *cs)
  - append_for_single_quote(const char *)
  All usage of append(const char*) is changed to either use
  String::append(char), String::append(const char*, size_t length) or
  String::append(LEX_CSTRING)
- Added STRING_WITH_LEN() around constant string arguments to
  String::append()
- Added overflow argument to escape_string_for_mysql() and
  escape_quotes_for_mysql() instead of returning (size_t) -1 on overflow.
  This was needed as most usage of the above functions never tested the
  result for -1 and would have given wrong results or crashes in case
  of overflows.
- Added Item_func_or_sum::func_name_cstring(), which returns LEX_CSTRING.
  Changed all Item_func::func_name()'s to func_name_cstring()'s.
  The old Item_func_or_sum::func_name() is now an inline function that
  returns func_name_cstring().str.
- Changed Item::mode_name() and Item::func_name_ext() to return
  LEX_CSTRING.
- Changed for some functions the name argument from const char * to
  to const LEX_CSTRING &:
  - Item::Item_func_fix_attributes()
  - Item::check_type_...()
  - Type_std_attributes::agg_item_collations()
  - Type_std_attributes::agg_item_set_converter()
  - Type_std_attributes::agg_arg_charsets...()
  - Type_handler_hybrid_field_type::aggregate_for_result()
  - Type_handler_geometry::check_type_geom_or_binary()
  - Type_handler::Item_func_or_sum_illegal_param()
  - Predicant_to_list_comparator::add_value_skip_null()
  - Predicant_to_list_comparator::add_value()
  - cmp_item_row::prepare_comparators()
  - cmp_item_row::aggregate_row_elements_for_comparison()
  - Cursor_ref::print_func()
- Removes String_space() as it was only used in one cases and that
  could be simplified to not use String_space(), thanks to the fixed
  my_vsnprintf().
- Added some const LEX_CSTRING's for common strings:
  - NULL_clex_str, DATA_clex_str, INDEX_clex_str.
- Changed primary_key_name to a LEX_CSTRING
- Renamed String::set_quick() to String::set_buffer_if_not_allocated() to
  clarify what the function really does.
- Rename of protocol function:
  bool store(const char *from, CHARSET_INFO *cs) to
  bool store_string_or_null(const char *from, CHARSET_INFO *cs).
  This was done to both clarify the difference between this 'store' function
  and also to make it easier to find unoptimal usage of store() calls.
- Added Protocol::store(const LEX_CSTRING*, CHARSET_INFO*)
- Changed some 'const char*' arrays to instead be of type LEX_CSTRING.
- class Item_func_units now used LEX_CSTRING for name.

Other things:
- Fixed a bug in mysql.cc:construct_prompt() where a wrong escape character
  in the prompt would cause some part of the prompt to be duplicated.
- Fixed a lot of instances where the length of the argument to
  append is known or easily obtain but was not used.
- Removed some not needed 'virtual' definition for functions that was
  inherited from the parent. I added override to these.
- Fixed Ordered_key::print() to preallocate needed buffer. Old code could
  case memory overruns.
- Simplified some loops when adding char * to a String with delimiters.
2021-05-19 22:27:48 +02:00
Monty
c6bf04ab2e Removed not used object Geometry::bad_geometry_data() 2021-05-19 22:27:28 +02:00
Marko Mäkelä
6c3e860cbf Merge 10.4 into 10.5 2021-04-14 11:35:39 +03:00
Marko Mäkelä
450c017c2d Merge 10.2 into 10.3 2021-04-09 14:32:06 +03:00
Marko Mäkelä
c6d0531cad MDEV-13467 fixup: Improve error handling 2021-04-08 09:46:56 +03:00
Eugene Kosov
4c80dcda46 fix gcc optimized build
../sql/spatial.cc: In member function ‘double Gis_point::calculate_haversine(const Geometry*, double, int*)’:
../sql/spatial.cc:1093:45: error: ‘y1r’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
 1093 |   res= 2*sphere_radius*asin((sqrt(dlat + cos(y1r)*cos(y2r)*dlong)));
      |                                          ~~~^~~~~
../sql/spatial.cc:1092:20: error: ‘x1r’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
 1092 |   dlong=  sin((x2r - x1r)/2)*sin((x2r - x1r)/2);
      |               ~~~~~^~~~~~
../sql/spatial.cc:1093:54: error: ‘y2r’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
 1093 |   res= 2*sphere_radius*asin((sqrt(dlat + cos(y1r)*cos(y2r)*dlong)));
      |                                                   ~~~^~~~~
../sql/spatial.cc:1092:20: error: ‘x2r’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
 1092 |   dlong=  sin((x2r - x1r)/2)*sin((x2r - x1r)/2);
      |               ~~~~~^~~~~~
c
2021-04-01 16:49:07 +03:00
Marko Mäkelä
5eae8c2742 Merge 10.4 into 10.5 2021-03-31 11:05:21 +03:00
Marko Mäkelä
d6d3d9ae2f Merge 10.2 into 10.3 2021-03-31 08:01:03 +03:00
Anel Husakovic
6769d1a078 MDEV-13467: Feature request: Support for ST_Distance_Sphere()
- Cherry-pick 51e48b9f89 - vscode gitignore
- Thanks Robin Dupret for the review.

Reviewed by:daniel@mariadb.org
            holyfoot@mariadb.com
2021-03-27 10:42:39 +01:00
Sergei Golubchik
25d9d2e37f Merge branch 'bb-10.4-release' into bb-10.5-release 2021-02-15 16:43:15 +01:00
Sergei Golubchik
60ea09eae6 Merge branch '10.2' into 10.3 2021-02-01 13:49:33 +01:00
Alexey Botchkov
959dfac4d0 MDEV-19723 Assertion je->state == JST_KEY' failed while SELECT ST_GEOMFROMGEOJSON() and Assertion !mysql_bin_log.is_open() || thd.is_current_stmt_binlog_format_row()'
The invalid GeoJSON case wasn't handled here.
2021-01-19 15:29:03 +04:00
Marko Mäkelä
5203bc10f1 Merge 10.4 into 10.5 2020-03-21 11:37:10 +02:00
Marko Mäkelä
44298e4dea Merge 10.2 into 10.3
Also, clean up the test innodb_gis.geometry a little further.
2020-03-20 18:12:17 +02:00
Alexey Botchkov
a0ce62f804 MDEV-14057 InnoDB GIS tests fail.
Tests fixed.
MBR::Within() function fixed.
2020-03-18 13:55:21 +04:00
Alexander Barkov
f1e13fdc8d MDEV-21581 Helper functions and methods for CHARSET_INFO 2020-01-28 12:29:23 +04:00
Alexander Barkov
e37d7a3715 MDEV-20006 Move geometry specific code in Field_blob::get_key_image() to Field_geom 2019-07-10 07:17:25 +04:00