[Commits] efa79c90820: MDEV-26724 Endless loop in json_escape_to_string upon ... empty string
revision-id: efa79c9082062c3f032f7f3ec12dc0a7a0ed3939 (mariadb-10.6.1-156-gefa79c90820) parent(s): 656dff97582cca416ecf5030ed114a610f8698df author: Sergei Petrunia committer: Sergei Petrunia timestamp: 2021-10-01 14:15:17 +0300 message: MDEV-26724 Endless loop in json_escape_to_string upon ... empty string Correctly handle empty string when [un]escaping JSON --- mysql-test/main/statistics_json.result | 16 ++++++++++++++++ mysql-test/main/statistics_json.test | 10 ++++++++++ sql/opt_histogram_json.cc | 4 ++-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/mysql-test/main/statistics_json.result b/mysql-test/main/statistics_json.result index 478fd1aefc2..549b60e1fe6 100644 --- a/mysql-test/main/statistics_json.result +++ b/mysql-test/main/statistics_json.result @@ -7853,3 +7853,19 @@ test.t1 analyze status OK select * from t1 where a = 'foo'; a drop table t1; +# +# MDEV-26724 Endless loop in json_escape_to_string upon ... empty string +# +CREATE TABLE t1 (f VARCHAR(8)); +INSERT INTO t1 VALUES ('a'),(''),('b'); +SET histogram_type=JSON_HB; +ANALYZE TABLE t PERSISTENT FOR ALL; +Table Op Msg_type Msg_text +test.t analyze Error Table 'test.t' doesn't exist +test.t analyze status Operation failed +select * from t1; +f +a + +b +drop table t1; diff --git a/mysql-test/main/statistics_json.test b/mysql-test/main/statistics_json.test index c8fa05c834a..518044c3343 100644 --- a/mysql-test/main/statistics_json.test +++ b/mysql-test/main/statistics_json.test @@ -193,3 +193,13 @@ analyze table t1 persistent for all; select * from t1 where a = 'foo'; drop table t1; +--echo # +--echo # MDEV-26724 Endless loop in json_escape_to_string upon ... empty string +--echo # +CREATE TABLE t1 (f VARCHAR(8)); +INSERT INTO t1 VALUES ('a'),(''),('b'); +SET histogram_type=JSON_HB; +ANALYZE TABLE t PERSISTENT FOR ALL; +select * from t1; +drop table t1; + diff --git a/sql/opt_histogram_json.cc b/sql/opt_histogram_json.cc index dc56a32d000..385d5b1e4e6 100644 --- a/sql/opt_histogram_json.cc +++ b/sql/opt_histogram_json.cc @@ -41,7 +41,7 @@ static bool json_unescape_to_string(const char *val, int val_len, String* out) (const uchar*)val + val_len, &my_charset_utf8mb4_bin, buf, buf + out->length()); - if (res > 0) + if (res >= 0) { out->length(res); return false; // Ok @@ -74,7 +74,7 @@ static bool json_escape_to_string(const char *val, int val_len, String* out) (const uchar*)val + val_len, &my_charset_utf8mb4_bin, buf, buf + out->length()); - if (res > 0) + if (res >= 0) { out->length(res); return false; // Ok
participants (1)
-
Sergei Petrunia