1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +03:00

MDEV-10425 Assertion `collation.derivation == DERIVATION_IMPLICIT' failed in Item_func_conv_charset::fix_length_and_dec()

MDEV-10850 Wrong result for WHERE .. (f2=TO_BASE64('test') OR f2=TO_BASE64('TEST'))

Problem N1: MDEV-10425
Item_func_{md5|sha|sha2}::fix_length_and_dec() changed args[0]->collation
to force binary comparison in args[0]->eq().
It was done to treat e.g. MD5('a') and MD5('A') as different values.
It is wrong for a Item_func_xxx to modify its arguments.
Item_func_conv_charset did not expect that and crashed on assert.

Problem N2: MDEV-10850
Item_func_to_base64, Item_func_password, Item_func_hex are also case sensitive
hash functions, but they did not compare their arguments as binary.

Solution:
- Removing the code changing args[0]->collation
- Introducing Item_str_ascii_checksum_func as a common parent
  for Item_func_{md5|sha|sha2|password|hex|to_base64}
  and overriding its eq() method to compare arguments binary.
This commit is contained in:
Alexander Barkov
2016-09-22 07:00:10 +04:00
parent ec7e0b7b30
commit 7e4eb990ad
9 changed files with 257 additions and 44 deletions

View File

@ -4581,6 +4581,62 @@ SELECT COUNT(*) FROM t1, t1 t2 GROUP BY INSERT('', t2.a, t1.a, @@global.max_binl
COUNT(*)
25
DROP TABLE t1;
# Start of func_str_ascii_checksum.inc
#
# MDEV-10850 Wrong result for WHERE .. (f2=TO_BASE64('test') OR f2=TO_BASE64('TEST'))
#
CREATE TABLE t1 (f1 VARCHAR(4), f2 VARCHAR(255), UNIQUE KEY k1 (f1,f2));
INSERT INTO t1 VALUES ('test',hex('test')), ('TEST', hex('TEST'));
SELECT * FROM t1 IGNORE INDEX(k1) WHERE f1='test' AND (f2= hex("test") OR f2= hex("TEST"));
f1 f2
test 74657374
TEST 54455354
SELECT * FROM t1 WHERE f1='test' AND (f2= hex("test") OR f2= hex("TEST"));
f1 f2
TEST 54455354
test 74657374
SELECT * FROM t1 WHERE f1='test' AND (f2= hex("TEST") OR f2= hex("test"));
f1 f2
TEST 54455354
test 74657374
DROP TABLE t1;
#
# MDEV-10425 Assertion `collation.derivation == DERIVATION_IMPLICIT' failed in Item_func_conv_charset::fix_length_and_dec()
#
PREPARE stmt FROM "SELECT hex(CONVERT('foo' USING latin1))";
EXECUTE stmt;
hex(CONVERT('foo' USING latin1))
666F6F
DEALLOCATE PREPARE stmt;
# End of func_str_ascii_checksum.inc
# Start of func_str_ascii_checksum.inc
#
# MDEV-10850 Wrong result for WHERE .. (f2=TO_BASE64('test') OR f2=TO_BASE64('TEST'))
#
CREATE TABLE t1 (f1 VARCHAR(4), f2 VARCHAR(255), UNIQUE KEY k1 (f1,f2));
INSERT INTO t1 VALUES ('test',to_base64('test')), ('TEST', to_base64('TEST'));
SELECT * FROM t1 IGNORE INDEX(k1) WHERE f1='test' AND (f2= to_base64("test") OR f2= to_base64("TEST"));
f1 f2
test dGVzdA==
TEST VEVTVA==
SELECT * FROM t1 WHERE f1='test' AND (f2= to_base64("test") OR f2= to_base64("TEST"));
f1 f2
test dGVzdA==
TEST VEVTVA==
SELECT * FROM t1 WHERE f1='test' AND (f2= to_base64("TEST") OR f2= to_base64("test"));
f1 f2
test dGVzdA==
TEST VEVTVA==
DROP TABLE t1;
#
# MDEV-10425 Assertion `collation.derivation == DERIVATION_IMPLICIT' failed in Item_func_conv_charset::fix_length_and_dec()
#
PREPARE stmt FROM "SELECT to_base64(CONVERT('foo' USING latin1))";
EXECUTE stmt;
to_base64(CONVERT('foo' USING latin1))
Zm9v
DEALLOCATE PREPARE stmt;
# End of func_str_ascii_checksum.inc
#
# End of 10.1 tests
#