Skip to content

Commit 496372d

Browse files
author
Alexander Barkov
committed
WL#5510 Functions to_base64 and from_base64
@ mysql-test/include/ctype_numconv.inc @ mysql-test/r/ctype_binary.result @ mysql-test/r/ctype_cp1251.result @ mysql-test/r/ctype_latin1.result @ mysql-test/r/ctype_ucs.result @ mysql-test/r/ctype_utf8.result @ mysql-test/r/func_str.result @ mysql-test/t/func_str.test Adding tests @ mysql-test/suite/binlog/r/binlog_base64_flag.result @ mysql-test/suite/binlog/t/binlog_base64_flag.test Fixing error from "syntax" error to "base64 decode" error for badly formed base64 input. @ include/base64.h Adding prototypes for *_max_arg_length() functions. @ mysys/base64.c Rewriting base64_decode, it's now 30% faster (using array instead of of strchr helps with that), and rejects garbage in input. Adding *_max_arg_length() functions. @ sql/item_create.cc Adding creators @ sql/item_strfunc.cc Implementing Item_func_to_base64 and Item_func_from_base64 @ sql/item_strfunc.h Adding prototype for Item_func_to_base64 and Item_func_from_base64 @ sql/sql_binlog.cc @ unittest/mysys/base64-t.c Passing 0 to the new "flag" argument.
1 parent 5138192 commit 496372d

17 files changed

+2189
-107
lines changed

include/base64.h

+14-1
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,21 @@ extern "C" {
2525
*/
2626
int base64_needed_encoded_length(int length_of_data);
2727

28+
/*
29+
Maximum length base64_encode_needed_length() can accept with no overflow.
30+
*/
31+
int base64_encode_max_arg_length(void);
32+
2833
/*
2934
Calculate how much memory needed for dst of base64_decode()
3035
*/
3136
int base64_needed_decoded_length(int length_of_encoded_data);
3237

38+
/*
39+
Maximum length base64_decode_needed_length() can accept with no overflow.
40+
*/
41+
int base64_decode_max_arg_length();
42+
3343
/*
3444
Encode data as a base64 string
3545
*/
@@ -39,7 +49,10 @@ int base64_encode(const void *src, size_t src_len, char *dst);
3949
Decode a base64 string into data
4050
*/
4151
int base64_decode(const char *src, size_t src_len,
42-
void *dst, const char **end_ptr);
52+
void *dst, const char **end_ptr, int flags);
53+
54+
/* Allow multuple chunks 'AAA= AA== AA==', binlog uses this */
55+
#define MY_BASE64_DECODE_ALLOW_MULTIPLE_CHUNKS 1
4356

4457

4558
#ifdef __cplusplus

mysql-test/include/ctype_numconv.inc

+12
Original file line numberDiff line numberDiff line change
@@ -1721,6 +1721,18 @@ DROP TABLE t1;
17211721
--echo # End of Bug#54916
17221722
--echo #
17231723

1724+
--echo #
1725+
--echo # WL#5510 Functions to_base64 and from_base64
1726+
--echo #
1727+
CREATE TABLE t1 AS SELECT TO_BASE64('test') AS to_base64;
1728+
SHOW CREATE TABLE t1;
1729+
SELECT to_base64, LENGTH(to_base64), HEX(to_base64) FROM t1;
1730+
CREATE TABLE t2 AS SELECT FROM_BASE64(to_base64) AS from_base64 FROM t1;
1731+
SHOW CREATE TABLE t2;
1732+
SELECT CAST(from_base64 AS CHAR), LENGTH(from_base64), HEX(from_base64) FROM t2;
1733+
DROP TABLE t2;
1734+
DROP TABLE t1;
1735+
17241736

17251737
--echo #
17261738
--echo # Bug#58190 BETWEEN no longer uses indexes for date or datetime fields

mysql-test/r/ctype_binary.result

+23
Original file line numberDiff line numberDiff line change
@@ -2767,6 +2767,29 @@ id select_type table type possible_keys key key_len ref rows Extra
27672767
1 SIMPLE t1 range date_column date_column 9 NULL 1 Using index condition
27682768
DROP TABLE t1;
27692769
#
2770+
# WL#5510 Functions to_base64 and from_base64
2771+
#
2772+
CREATE TABLE t1 AS SELECT TO_BASE64('test') AS to_base64;
2773+
SHOW CREATE TABLE t1;
2774+
Table Create Table
2775+
t1 CREATE TABLE `t1` (
2776+
`to_base64` varbinary(8) NOT NULL DEFAULT ''
2777+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
2778+
SELECT to_base64, LENGTH(to_base64), HEX(to_base64) FROM t1;
2779+
to_base64 LENGTH(to_base64) HEX(to_base64)
2780+
dGVzdA== 8 6447567A64413D3D
2781+
CREATE TABLE t2 AS SELECT FROM_BASE64(to_base64) AS from_base64 FROM t1;
2782+
SHOW CREATE TABLE t2;
2783+
Table Create Table
2784+
t2 CREATE TABLE `t2` (
2785+
`from_base64` varbinary(6) DEFAULT NULL
2786+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
2787+
SELECT CAST(from_base64 AS CHAR), LENGTH(from_base64), HEX(from_base64) FROM t2;
2788+
CAST(from_base64 AS CHAR) LENGTH(from_base64) HEX(from_base64)
2789+
test 4 74657374
2790+
DROP TABLE t2;
2791+
DROP TABLE t1;
2792+
#
27702793
# Bug#52159 returning time type from function and empty left join causes debug assertion
27712794
#
27722795
CREATE FUNCTION f1() RETURNS TIME RETURN 1;

mysql-test/r/ctype_cp1251.result

+23
Original file line numberDiff line numberDiff line change
@@ -3157,6 +3157,29 @@ id select_type table type possible_keys key key_len ref rows Extra
31573157
1 SIMPLE t1 range date_column date_column 9 NULL 1 Using index condition
31583158
DROP TABLE t1;
31593159
#
3160+
# WL#5510 Functions to_base64 and from_base64
3161+
#
3162+
CREATE TABLE t1 AS SELECT TO_BASE64('test') AS to_base64;
3163+
SHOW CREATE TABLE t1;
3164+
Table Create Table
3165+
t1 CREATE TABLE `t1` (
3166+
`to_base64` varchar(8) CHARACTER SET cp1251 NOT NULL DEFAULT ''
3167+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
3168+
SELECT to_base64, LENGTH(to_base64), HEX(to_base64) FROM t1;
3169+
to_base64 LENGTH(to_base64) HEX(to_base64)
3170+
dGVzdA== 8 6447567A64413D3D
3171+
CREATE TABLE t2 AS SELECT FROM_BASE64(to_base64) AS from_base64 FROM t1;
3172+
SHOW CREATE TABLE t2;
3173+
Table Create Table
3174+
t2 CREATE TABLE `t2` (
3175+
`from_base64` varbinary(6) DEFAULT NULL
3176+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
3177+
SELECT CAST(from_base64 AS CHAR), LENGTH(from_base64), HEX(from_base64) FROM t2;
3178+
CAST(from_base64 AS CHAR) LENGTH(from_base64) HEX(from_base64)
3179+
test 4 74657374
3180+
DROP TABLE t2;
3181+
DROP TABLE t1;
3182+
#
31603183
# Bug#52159 returning time type from function and empty left join causes debug assertion
31613184
#
31623185
CREATE FUNCTION f1() RETURNS TIME RETURN 1;

mysql-test/r/ctype_latin1.result

+23
Original file line numberDiff line numberDiff line change
@@ -3177,6 +3177,29 @@ id select_type table type possible_keys key key_len ref rows Extra
31773177
1 SIMPLE t1 range date_column date_column 9 NULL 1 Using index condition
31783178
DROP TABLE t1;
31793179
#
3180+
# WL#5510 Functions to_base64 and from_base64
3181+
#
3182+
CREATE TABLE t1 AS SELECT TO_BASE64('test') AS to_base64;
3183+
SHOW CREATE TABLE t1;
3184+
Table Create Table
3185+
t1 CREATE TABLE `t1` (
3186+
`to_base64` varchar(8) NOT NULL DEFAULT ''
3187+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
3188+
SELECT to_base64, LENGTH(to_base64), HEX(to_base64) FROM t1;
3189+
to_base64 LENGTH(to_base64) HEX(to_base64)
3190+
dGVzdA== 8 6447567A64413D3D
3191+
CREATE TABLE t2 AS SELECT FROM_BASE64(to_base64) AS from_base64 FROM t1;
3192+
SHOW CREATE TABLE t2;
3193+
Table Create Table
3194+
t2 CREATE TABLE `t2` (
3195+
`from_base64` varbinary(6) DEFAULT NULL
3196+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
3197+
SELECT CAST(from_base64 AS CHAR), LENGTH(from_base64), HEX(from_base64) FROM t2;
3198+
CAST(from_base64 AS CHAR) LENGTH(from_base64) HEX(from_base64)
3199+
test 4 74657374
3200+
DROP TABLE t2;
3201+
DROP TABLE t1;
3202+
#
31803203
# Bug#52159 returning time type from function and empty left join causes debug assertion
31813204
#
31823205
CREATE FUNCTION f1() RETURNS TIME RETURN 1;

mysql-test/r/ctype_ucs.result

+23
Original file line numberDiff line numberDiff line change
@@ -4075,6 +4075,29 @@ id select_type table type possible_keys key key_len ref rows Extra
40754075
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where
40764076
DROP TABLE t1;
40774077
#
4078+
# WL#5510 Functions to_base64 and from_base64
4079+
#
4080+
CREATE TABLE t1 AS SELECT TO_BASE64('test') AS to_base64;
4081+
SHOW CREATE TABLE t1;
4082+
Table Create Table
4083+
t1 CREATE TABLE `t1` (
4084+
`to_base64` varchar(12) CHARACTER SET ucs2 NOT NULL DEFAULT ''
4085+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
4086+
SELECT to_base64, LENGTH(to_base64), HEX(to_base64) FROM t1;
4087+
to_base64 LENGTH(to_base64) HEX(to_base64)
4088+
AHQAZQBzAHQ= 24 0041004800510041005A00510042007A004100480051003D
4089+
CREATE TABLE t2 AS SELECT FROM_BASE64(to_base64) AS from_base64 FROM t1;
4090+
SHOW CREATE TABLE t2;
4091+
Table Create Table
4092+
t2 CREATE TABLE `t2` (
4093+
`from_base64` varbinary(18) DEFAULT NULL
4094+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
4095+
SELECT CAST(from_base64 AS CHAR), LENGTH(from_base64), HEX(from_base64) FROM t2;
4096+
CAST(from_base64 AS CHAR) LENGTH(from_base64) HEX(from_base64)
4097+
test 8 0074006500730074
4098+
DROP TABLE t2;
4099+
DROP TABLE t1;
4100+
#
40784101
# Bug#52159 returning time type from function and empty left join causes debug assertion
40794102
#
40804103
CREATE FUNCTION f1() RETURNS TIME RETURN 1;

mysql-test/r/ctype_utf8.result

+23
Original file line numberDiff line numberDiff line change
@@ -4989,6 +4989,29 @@ id select_type table type possible_keys key key_len ref rows Extra
49894989
1 SIMPLE t1 range date_column date_column 9 NULL 1 Using index condition
49904990
DROP TABLE t1;
49914991
#
4992+
# WL#5510 Functions to_base64 and from_base64
4993+
#
4994+
CREATE TABLE t1 AS SELECT TO_BASE64('test') AS to_base64;
4995+
SHOW CREATE TABLE t1;
4996+
Table Create Table
4997+
t1 CREATE TABLE `t1` (
4998+
`to_base64` varchar(16) CHARACTER SET utf8 NOT NULL DEFAULT ''
4999+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
5000+
SELECT to_base64, LENGTH(to_base64), HEX(to_base64) FROM t1;
5001+
to_base64 LENGTH(to_base64) HEX(to_base64)
5002+
dGVzdA== 8 6447567A64413D3D
5003+
CREATE TABLE t2 AS SELECT FROM_BASE64(to_base64) AS from_base64 FROM t1;
5004+
SHOW CREATE TABLE t2;
5005+
Table Create Table
5006+
t2 CREATE TABLE `t2` (
5007+
`from_base64` varbinary(36) DEFAULT NULL
5008+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
5009+
SELECT CAST(from_base64 AS CHAR), LENGTH(from_base64), HEX(from_base64) FROM t2;
5010+
CAST(from_base64 AS CHAR) LENGTH(from_base64) HEX(from_base64)
5011+
test 4 74657374
5012+
DROP TABLE t2;
5013+
DROP TABLE t1;
5014+
#
49925015
# Bug#52159 returning time type from function and empty left join causes debug assertion
49935016
#
49945017
CREATE FUNCTION f1() RETURNS TIME RETURN 1;

0 commit comments

Comments
 (0)