1
0
mirror of https://github.com/MariaDB/server.git synced 2025-11-09 11:41:36 +03:00

MDEV-30691 Assertion `strlen(Ptr) == str_length' failed in void Binary_string::chop()

numerous bugs in JSON_DETAILED and multibyte charsets:

* String:chop() must be charset-aware and not simply length--
* String::append(char) must be charset-aware and not simply length++
* json_nice() first removes value_len bytes, then a
  certain number of characters
This commit is contained in:
Sergei Golubchik
2025-08-06 19:45:38 +02:00
parent ed81e5f456
commit 59d679a383
5 changed files with 41 additions and 39 deletions

View File

@@ -374,37 +374,6 @@ public:
!memcmp(ptr(), other->ptr(), length());
}
/*
PMG 2004.11.12
This is a method that works the same as perl's "chop". It simply
drops the last character of a string. This is useful in the case
of the federated storage handler where I'm building a unknown
number, list of values and fields to be used in a sql insert
statement to be run on the remote server, and have a comma after each.
When the list is complete, I "chop" off the trailing comma
ex.
String stringobj;
stringobj.append("VALUES ('foo', 'fi', 'fo',");
stringobj.chop();
stringobj.append(")");
In this case, the value of string was:
VALUES ('foo', 'fi', 'fo',
VALUES ('foo', 'fi', 'fo'
VALUES ('foo', 'fi', 'fo')
*/
inline void chop()
{
if (str_length)
{
str_length--;
Ptr[str_length]= '\0';
DBUG_ASSERT(strlen(Ptr) == str_length);
}
}
// Returns offset to substring or -1
int strstr(const Binary_string &search, uint32 offset=0) const;
int strstr(const char *search, uint32 search_length, uint32 offset=0) const;
@@ -1039,7 +1008,7 @@ public:
}
inline bool append(char chr)
{
return Binary_string::append_char(chr);
return append(&chr, 1);
}
bool append_hex(const char *src, uint32 srclen)
{
@@ -1162,6 +1131,15 @@ public:
return false;
}
inline void chop()
{
if (str_length)
{
str_length--;
str_length= well_formed_length();
}
}
void strip_sp();
friend String *copy_if_not_alloced(String *a,String *b,uint32 arg_length);
friend class Field;