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

1893 Commits

Author SHA1 Message Date
forkfun
08eeb6a417 Merge branch '10.11' into '11.4' 2026-07-28 13:14:38 +02:00
Daniel Black
d3afdd162b MDEV-35738 mariadb build -fsanitize=pointer-compare
invalid pointer pairs are when the length/memory of one string are
intermixed with another.

For comp_err, the end null pointer was compared to soffset within
my_strtoll10. As we didn't need the end position a NULL arg option
was compatble.

For uca-dump, Address Sanitizer raises invalid pointer pair because
argv options (opt) don't have an obvious correlation of having a start
at opt_X.length, even though the lstrncmp makes this true.

The DBUG_ASSERTS of strmov (added MDEV-11752) where incompatible with
pointer-compare. Replaced strmov with static inline version in
m_string.h using memmove that allows overlaps, and being inline allows
the uneeded parts of the implementation to be optimized away.
2026-07-25 13:44:37 +10:00
Daniel Black
c4f538f6a9 MDEV-28922 JSON_NORMALIZE handling of duplicate keys
Despite the JSON spec rfc8259/#section-4
"The names within an object SHOULD be unique"[1], it does happen.

As our sort algorithm has access to both key and value,
if the key matches, sort by the value. The type, and length of
objects, strings, arrays and numbers is easy, so use those as a
first comparision point.

[1] https://www.rfc-editor.org/info/rfc8259/#section-4
2026-07-16 13:10:21 +10:00
Daniel Black
0a31f7aeba MDEV-40175: JSON_VALID (postfix)
a90779098b changed the
interface to the json_valid to take a json_engine_t
so that it could be interupted and so that warnings
could become visible.

On merge from that 10.11 to 11.4 it was discovered
that the ColumnStore engine uses this interface.

Restored the original json_valid function exactly
how ColumnStore expects this and added renamed
the function with json_engine_t to be json_valid_engine.

This follows the same convention as in the commit
756fc6fd9a that was
for json_normalize, that ColumnStore also used.
2026-07-16 09:02:45 +10:00
Daniel Black
78f8a49ed2 MDEV-40175: JSON_VALID (postfix)
a90779098b changed the
interface to the json_valid to take a json_engine_t
so that it could be interupted and so that warnings
could become visible.

On merge from that 10.11 to 11.4 it was discovered
that the ColumnStore engine uses this interface.

Restored the original json_valid function exactly
how ColumnStore expects this and added renamed
the function with json_engine_t to be json_valid_engine.

This follows the same convention as in the commit
756fc6fd9a that was
for json_normalize, that ColumnStore also used.
2026-07-16 09:01:16 +10:00
Daniel Black
e94ae88e1a MDEV-40165: json_normalize (fix)
14c16e02b2 changed the
interface for json_normalize to take a json_engine_t so that
there could be some error checking.

Unfortunately ColumnStore depended on this interface.

Restored original interface of json_normalize() and
added a json_normalize_engine() that take as engine as the
argument.
2026-07-16 09:01:16 +10:00
Daniel Black
756fc6fd9a MDEV-40165: json_normalize (fix)
14c16e02b2 changed the
interface for json_normalize to take a json_engine_t so that
there could be some error checking.

Unfortunately ColumnStore depended on this interface.

Restored original interface of json_normalize() and
added a json_normalize_engine() that take as engine as the
argument.
2026-07-15 16:21:59 +10:00
Daniel Black
1e972a8d70 Merge 10.11 into 11.4 2026-07-14 12:49:36 +10:00
Daniel Black
a90779098b MDEV-40175: JSON_VALID don't respect KILL QUERY
Or max_statement_time limit.

Change the json_valid to take a json_engine_t argument.
Adjust the Item_json_valid to have a json_engine_t and
to report an error.

Note this means that invalid json syntax now has a
note on any json error. Raising this to a warning can
cause check constraints of JSON_VALID() to result
in ER_JSON_SYNTAX rather than ER_CONSTRAINT_FAILED
(valided in main.type_json test).

Consequential changes in debug build to json acl
testing validation and unit test having a dummy json_engine_t.

json_normalize also uses the same engine that was
passed as its argument to test json_valid. Because
the character set may have changed, if there's an error
adjust the je->s.c_str pointer. Its only the offset that
is currently used in the error messages anyway so there
may be offset errors depending on the original character
set.
2026-07-14 11:59:00 +10:00
Daniel Black
14c16e02b2 MDEV-40165: JSON_EQUAL/JSON_NORMALIZE dont respect KILL QUERY
Or max_statement_time limit.

JSON_EQUAL/JSON_NORMALIZE also didn't report warnings
on invalid JSON inputs.

Change the json_normalize function to take a json_engine_t
as a argument and implement the sql/item_jsonfunc.cc calls
to have a json_engine_t.

To the JSON_EQUALS and JSON_NORMALIZE, add error handling
to produce an error when there was one. compare_nested_object,
part of JSON_OVERLAPS, uses a new json_engine and
copies the error/position to the returning function.

json_normalize expects the incoming je structure to have
a valid, or nullptr, killed_ptr, as json_start will reset this.
2026-07-14 11:59:00 +10:00
Hemant Dangi
051f7d9541 MDEV-40280: FreeBSD galera.galera_max_ws_rows test failure
Issue:
For unknown error numbers, BSD-derived libc (macOS, FreeBSD, ...) formats
"Unknown error: <n>" with a colon, while glibc uses "Unknown error <n>".
my_strerror()'s colon-stripping (MDEV-35578) was gated on __APPLE__ only,
so FreeBSD output diverged from the .result.

Solution:
Normalize by behavior instead of by platform: always strip the colon after
"Unknown error". glibc never emits it, so it is a no-op there, and
macOS/FreeBSD/other BSD libc are all covered without enumeration. This is
what MDEV-35578 already intended ("consistent across the platforms ...
when present"); the __APPLE__ guard was just narrower than that intent.
Runs only in the unknown-error path.
2026-07-13 15:07:00 +10:00
Syed Mohammed Nayyar
fb7ffd4f48 MDEV-40201: bound the trailing hex read in my_mb_wc_filename
Problem:
my_mb_wc_filename() decodes the my_charset_filename '@HHHH' escape, which
is 5 bytes, but the length guard only required 4 (s[0..3]) before the hex
branch read the 4th hex digit at s[4]. A truncated escape whose end
pointer sits at s+4 (reachable through well_formed_length()/charpos() on a
my_charset_filename string with a tight, non-terminated bound) read one
byte past e.

Fix/Solution:
A 4-byte escape is not valid, so require all 5 bytes up front: s + 5 > e
now returns MY_CS_TOOSMALL5. The read of s[4] keeps the s[3] guard,
because 'e' may be fake (see the strconvert() note above the function):
a NUL-terminated input such as "@00\0" with an over-long end must still
stop at the terminator instead of reading s[4]. Added a strings-t case
covering both the tight-end (MY_CS_TOOSMALL5) and the NUL-terminated
(MY_CS_ILSEQ) truncations.
2026-07-07 16:09:44 +05:30
Raghunandan Bhat
943567aac7 MDEV-39744: Assertion buf != end failed in decimal_mul
Problem:
  With `div_precision_increment=0`, a division whose quotient rounds
  away to zero (e.g. -299/450) produced a decimal with no digit words
  (intg=0 and frac=0) while still keeping the sign bit set. That is a
  malformed value.

  Multiplying such a malformed zero value by another zero reached the
  negative-zero check in `decimal_mul`, where there were no digit words
  to scan, leading to assertion failure.

Fix:
  Fix `do_div_mod`, which produced the malformed zero. `do_div_mod`
  already normalizes this case to a canonical zero on the modulo path;
  do the same on the division path: when the quotient has no digits
  (intg0 = 0 && frac0 = 0) return a correct decimal zero instead of a
  digit-less, signed value.
2026-07-03 09:52:59 +05:30
Raghunandan Bhat
a9132af90f MDEV-39690: UBSAN: signed integer overflow in my_strntoll_8bit, my_strntoll_mb2_or_mb4 during BLOB-to-integer conversion
Problem:
  When converting a string like '-9223372036854775808' to an integer,
  the parsed magnitude (2^63) equals `(ulonglong) LONGLONG_MIN` and is
  accepted as valid. The return expression then cast it to signed
  (LONGLONG_MIN) and negated it. Negating LONGLONG_MIN is signed integer
  overflow, i.e. undefined behaviour.

Fix:
  Handle the boundary value explicitly. When the parsed magnitude equals
  `(ulonglong) LONGLONG_MIN`, return LONGLONG_MIN directly. Any smaller
  magnitude fits in a positive longlong, so the existing cast and
  negation stay well defined.

Backport from 11.4 commit - f552febe43
2026-06-30 12:51:23 +05:30
Daniel Black
f41aca23bf MDEV-40176: UBSAN: runtime error: applying non-zero offset in my_charpos_mb (2)
my_numchars_mb and my_charpos_mb both used their cs argument
so remove the notused attribute on them.
2026-06-30 08:36:32 +10:00
Raghunandan Bhat
e3dd55c0d1 MDEV-40176: UBSAN: runtime error: applying non-zero offset in my_charpos_mb
Problem:
  When `my_charpos_mb()` is called with pos = end = NULL and the string
  has fewer than `length` characters, the `end + 2 - start` return
  expression evaluates `end+2`, forming the pointer NULL+2. Offsetting
  a null pointer is undefined behavior.

Fix:
  Compute the integer difference before adding the offset. The result is
  identical but no invalid pointer is ever formed.
2026-06-30 08:36:32 +10:00
Marko Mäkelä
3ce999df6b Merge 10.11 into 11.4 2026-06-26 13:45:38 +03:00
Daniel Black
f249b0196d Merge 10.6 into 10.11 2026-06-26 17:56:20 +10:00
Daniel Black
24ee5fd6bf MDEV-28404 JSON functions don't respect KILL QUERY
Or max_statement_time limit or MAX_DEPTH.

Correct interuptability and depth checking of:
* JSON_CONTAINS
* JSON_CONTAINS_PATH
* JSON_EXISTS
* JSON_EXTRACT
* JSON_KEYS
* ST_GeomFromGeoJSON

Populate in the json library the killed as a specific
error message. As the json library has a killed_ptr
is approprate it handles it.

As json_report_error now processes the killed there's
no need of thd->check_killed().

Verified that the path after every json_scan_next, the
location of checking the killed_ptr, reports errors
correctly.
2026-06-26 07:32:21 +03:00
Daniel Black
0ff2fda7b3 MDEV-30518: JSON functions cannot be killed on big-endian (backport)
Backport to 10.6 without JSON_OVERLAPS

The json_engine killed_ptr was of type uchar however the enum
in the server is dependant on the architecture. On big-endian
architectures like IBM Z, retreiving a uchar* retreived the
unmodifed part of the THD->kill enum location and was always 0.

As C++11 allows enums to inherit a type, used uint32_t as the base
class of killed_state type in the server and used uint32_t in the
json library.

reload_acl_and_cache required an expression change to avoid
the compile error:
sql/sql_reload.cc:472:24: error: enumerated and non-enumerated
type in conditional expression [-Werror=enum-conversion]
  472 |  return result || (thd ? thd->killed : 0);

Added the kill_ptr assignment the following functions can be
killed:
* Item_func_json_depth::val_int
* Item_func_json_type::val_str
* Item_func_json_length::val_int

Item_func_json_array_append::val_str, check_killed() only applied
to json_error: label and not return_null.

Item_func_json_format::val_str(), corresponding to the SQL,
json_compact, json_detailed, json_loose - add debug instrumentation
for the func_json_notembedded test.

MDEV-26726 (fcd345de48) added a json_pause_execution sync point
however the test case used debug_max_statement_time, which doesn't
exist. Fix the sync point name in the test.
2026-06-26 07:32:21 +03:00
Kristian Nielsen
85ec122c15 Merge 10.11 to 11.4
Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
2026-06-15 12:50:45 +02:00
Marko Mäkelä
b89cb5d5c7 Merge mariadb-10.11.17 into 10.11 2026-05-19 08:12:14 +03:00
Daniel Black
509e40e706 MDEV-30518: JSON functions cannot be killed on big-endian
The json_engine killed_ptr was of type uchar however the enum
in the server is dependant on the architecture. On big-endian
architectures like IBM Z, retreiving a uchar* retreived the
unmodifed part of the THD->kill enum location and was always 0.

As C++11 allows enums to inherit a type, used uint32_t as the base
class of killed_state type in the server and used uint32_t in the
json library.

reload_acl_and_cache required an expression change to avoid
the compile error:
sql/sql_reload.cc:472:24: error: enumerated and non-enumerated
type in conditional expression [-Werror=enum-conversion]
  472 |  return result || (thd ? thd->killed : 0);

Added the kill_ptr assignment the following functions can be
killed:
* Item_func_json_depth::val_int
* Item_func_json_type::val_str
* Item_func_json_length::val_int

Item_func_json_array_append::val_str, check_killed() only applied
to json_error: label and not return_null.

Item_func_json_overlaps::val_bool ensure check_killed() is called.

Item_func_json_format::val_str(), corresponding to the SQL,
json_compact, json_detailed, json_loose - add debug instrumentation
for the func_json_notembedded test.

MDEV-26726 (fcd345de48) added a json_pause_execution sync point
however the test case used debug_max_statement_time, which doesn't
exist. Fix the sync point name in the test.
2026-05-14 08:44:01 +10:00
Oleksandr Byelkin
7598e4e95d Merge branch '10.11' into 11.4 2026-05-08 08:00:01 +02:00
Oleksandr Byelkin
6828ff7390 Merge branch '10.6' into 10.11 2026-05-08 07:38:22 +02:00
Rucha Deodhar
902d05a22a MDEV-39213: json range syntax crash
Analysis:
When json is being parsed, the step decreases without a out-of-bound check
resulting in failure.
Fix:
Before decreasing the step, check if it will result into out of bound.
2026-05-07 14:39:35 -04:00
Varun Deep Saini
551c980587 MDEV-35548: Fix out-of-bounds array access in json_get_path_start
json_get_path_start() set p->last_step to p->steps - 1, creating a
pointer before the beginning of the steps[] array. This is undefined
behavior flagged by UBSAN as "index -1 out of bounds for type
json_path_step_t[32]".

Use NULL as the sentinel value instead, and check for NULL in
json_get_path_next() rather than comparing against p->steps.

Backport to 10.6 of commit 4f546897b8.

Additional test case from Rucha Deodhar

Signed-off-by: Varun Deep Saini <varun.23bcs10048@ms.sst.scaler.com>
Signed-off-by: Varun Deep Saini <deepsainivarun@gmail.com>
2026-05-05 15:48:12 +02:00
Varun Deep Saini
4f546897b8 MDEV-35548: Fix out-of-bounds array access in json_get_path_start
json_get_path_start() set p->last_step to p->steps - 1, creating a
pointer before the beginning of the steps[] array. This is undefined
behavior flagged by UBSAN as "index -1 out of bounds for type
json_path_step_t[32]".

Use NULL as the sentinel value instead, and check for NULL in
json_get_path_next() rather than comparing against p->steps.

Signed-off-by: Varun Deep Saini <varun.23bcs10048@ms.sst.scaler.com>
Signed-off-by: Varun Deep Saini <deepsainivarun@gmail.com>
2026-04-21 12:23:14 +10:00
Marko Mäkelä
58f507206f Merge 10.6 into 10.11 2026-04-20 11:07:30 +03:00
Sergei Golubchik
f0bcd1995d MDEV-17256 Decimal field multiplication bug
Fix multiplication correctly - by truncating long factors before
multiplication. Not both equally, but in a way that minimizes the
error.

Add more multiplication tests to verify that now multiplication
works correctly.
2026-04-19 11:36:16 +02:00
Sergei Golubchik
da20c1754c MDEV-30255 0 changed to 0.0 caused by DISTINCT and UNION ALL
Revert "MDEV-17256 Decimal field multiplication bug." (57898316b6)

It removes zero truncation from decimal_mul() and fixes
reported symptoms.

But reintroduces multiplication bug.
2026-04-19 11:36:16 +02:00
Alexey Botchkov
8d0feb2072 MDEV-39210 ExtractValue/UpdateXML crash.
XML parser fixed to handle <! and <? correctly.
2026-04-19 00:45:57 +04:00
Mikhail Pochatkin
cbcff6324a MDEV-39173 Replace sprintf with snprintf, remove deprecated pragma
Remove the unscoped #pragma GCC diagnostic ignored
"-Wdeprecated-declarations" from include/violite.h and replace all
sprintf/vsprintf calls with snprintf/vsnprintf across the codebase.

Where possible, pass actual buffer sizes as function parameters
instead of using hardcoded constants or recomputing strlen().
Notable API changes:
- get_date(): added to_len parameter for buffer size
- nice_time(), end_timer() in client/mysql.cc: added buff_size
- generate_new_name(): added name_size parameter
- calc_md5(): added buffer_size parameter (fixes off-by-one)
- MD5_HASH_TO_STRING macro: added _size parameter
- Added MYSQL_UDF_MAX_RESULT_LENGTH constant in mysql_com.h

Also fixed a pre-existing bug in sql/rpl_mi.cc where the ellipsis
"..." was written to the wrong buffer (dbuff instead of buff).

Vendored code is excluded: extra/readline, extra/wolfssl,
wsrep-lib, libmariadb, storage/mroonga/vendor, zlib.
2026-04-16 19:00:12 +10:00
abdelrahim
12e09fefc7 MDEV-38670 Unary minus on empty string returns -0
Normalize -0.0 to +0.0 in Item_func_neg::real_op() to match
binary subtraction behavior. Add test case in type_newdecimal.

add result for tests

fix tests

Revert whitespace changes in type_newdecimal.result

Revert whitespace changes in type_newdecimal.test

normalize all real_op functions in item_func.cc and item_cmpfunc.cc to convert -0.0 to 0.0

normalize all real_op functions in item_func.cc and item_cmpfunc.cc to convert -0.0 to 0.0

normalize all real_op functions in item_func.cc and item_cmpfunc.cc to convert -0.0 to 0.0

normalize all real_op functions in item_func.cc and item_cmpfunc.cc to convert -0.0 to 0.0

normalize -0.0 to 0.0

normalize -0.0 to 0.0

Revert unintended changes in item_func.h

Revert unintended changes in item_func.h (10.6)

fix dtoa.cc and feild.cc and remove past edits

fix buildbot/amd64-ubuntu-2204-debug-ps failed test

fix result which print (-0,0)

rm

fix typo

fix typo
2026-04-10 10:48:13 +04:00
Marko Mäkelä
7c5cac0d51 Merge 10.11 into 11.4 2026-04-01 10:49:05 +03:00
Abhishek Bansal
9bd0ea0d03 MDEV-38264: Fix failed assertion in json_find_path with trailing commas
The function json_skip_array_and_count() was trapping syntax errors
(e.g., trailing commas) in a local engine copy. Because the error state
wasn't propagated back to the main engine, json_find_path() would
proceed with an inconsistent state, eventually triggering an assertion
failure.

This patch ensures that any error encountered during the lookahead
scan is propagated to the primary engine. This allows the parser to
fail gracefully with a syntax error instead of crashing.
2026-03-30 15:27:31 +03:00
Marko Mäkelä
3fe04b1e18 Merge 10.11 into 11.4 2026-03-17 11:30:41 +02:00
Marko Mäkelä
1e639cb76d Merge 10.6 into 10.11 2026-03-17 11:05:34 +02:00
Vladislav Vaintroub
d116cace9b Revert "MDEV-38989 main.ctype_utf16le SEGV in Ubuntu 26.04 (x86-64-v3)"
This reverts commit 6318d50015.

uint2korr is now fixed in MDEV-37788, thus partial workarounds are not necessary anymore.
2026-03-13 08:28:14 +01:00
Brian White
1abec9a9f8 fix build with WITH_EXTRA_CHARSETS=none again 2026-03-13 11:39:14 +11:00
Marko Mäkelä
a6c9013965 Merge 10.11 into 11.4 2026-03-11 14:18:49 +02:00
Marko Mäkelä
0c6c9bf91b Merge 10.6 into 10.11 2026-03-06 12:07:53 +02:00
Marko Mäkelä
6318d50015 MDEV-38989 main.ctype_utf16le SEGV in Ubuntu 26.04 (x86-64-v3)
my_utf16le_uni(), my_lengthsp_utf16le(): Instead of wrongly claiming
aligned access by invoking uint2korr(), inform the compiler of
unaligned access by invoking memcpy(), which will be optimized away.
2026-03-06 09:38:14 +02:00
Sergei Golubchik
40f7084661 Merge branch '10.11' into 11.4 2026-01-28 21:52:18 +01:00
Sergei Golubchik
b29d3779e4 Merge branch '10.6' into 10.11 2026-01-28 14:22:20 +01:00
Marko Mäkelä
470487c1a6 MDEV-21816 Suboptimal implementation of my_convert()
my_convert(): Correctly identify unaligned access by invoking memcpy(),
which will be translated to a single x86 MOV instruction already by
GCC 4.8.5. Also, process the data 64 bits at a time when possible.

The use of memcpy() prevents GCC from emitting a SIMD instruction that
expects aligned memory (MDEV-37148, MDEV-37786, MDEV-38398) and
allows us to enable the fast path across all ISA.

Reviewed by: Alexander Barkov
Reviewed by: Vladislav Vaintroub
2026-01-21 14:16:00 +02:00
Oleksandr Byelkin
15b1426c3a Merge branch '10.11' into bb-11.4-release 2025-09-15 16:17:33 +02:00
Daniel Black
f609dbd39b MDEV-30692: conf_to_src incompatible with CHARSET_INFO changes (postfix)
Caused by MDEV-30577 when the CHARSET_INFO structure changed.

As hinted by clang:

error: no member named 'csname' in 'struct charset_info_st'; did you mean 'cs_name'?

Because the target conf_to_src has the properties EXCLUDE_FROM_DEFAULT_BUILD
it hasn't been noticed.

Also correct:

 warning: field precision should have type 'int', but argument has type 'size_t'
2025-09-10 13:50:59 +10:00
Sergei Golubchik
c4ed889b74 Merge branch '10.11' into 11.4 2025-07-28 19:40:10 +02:00
Sergei Golubchik
053f9bcb5b Merge branch '10.6' into 10.11 2025-07-28 18:06:31 +02:00