Skip to content

Commit 3fc00c8

Browse files
author
Bin Su
committed
BUG#21542698 - LOAD DATA INFILE: ASSERTION FAILED: ML == 2 || ML == 4
This is due to a too strict assertion, which could not handle the invlaid characters. We just have to accept the invalid characters in the assertion. Reviewed-by: Roy Lyseng <Roy.lyseng@oracle.com>
1 parent 128a99a commit 3fc00c8

File tree

5 files changed

+16
-4
lines changed

5 files changed

+16
-4
lines changed

include/m_ctype.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,8 @@ uint my_mbcharlen_ptr(const CHARSET_INFO *cs, const char *s, const char *e);
764764
@param[in] a first byte of gb18030 code
765765
@param[in] b second byte of gb18030 code
766766
@return the length of gb18030 code starting with given two bytes,
767-
the length would be 2 or 4
767+
the length would be 2 or 4 for valid gb18030 code,
768+
or 0 for invalid gb18030 code
768769
*/
769770
#define my_mbcharlen_2(s, a, b) ((s)->cset->mbcharlen((s),((((a) & 0xFF) << 8) + ((b) & 0xFF))))
770771
/**

mysql-test/r/ctype_gb18030.result

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,6 +1795,10 @@ CCE7 1
17951795
99CC 1
17961796
8BF5819AEDC3 1
17971797
DROP TABLE t1;
1798+
CREATE TABLE t1 (a int) ENGINE=InnoDB;
1799+
LOAD DATA INFILE '../../std_data/bug21542698.dat' INTO TABLE t1 CHARACTER SET gb18030;
1800+
ERROR HY000: Invalid gb18030 character string: 'MZ'
1801+
DROP TABLE t1;
17981802
DROP DATABASE gb18030;
17991803
SET sql_mode = default;
18001804
#

mysql-test/std_data/bug21542698.dat

1 KB
Binary file not shown.

mysql-test/t/ctype_gb18030.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,12 @@ INSERT INTO t1 VALUES (_gb18030 0x8BF5819AEDC3), (_gb18030 0x99CC), (_gb18030 0x
258258
SELECT ANY_VALUE(HEX(c)), COUNT(c) FROM t1 GROUP BY c COLLATE gb18030_chinese_ci;
259259
DROP TABLE t1;
260260

261+
# Test if LOAD DATA with gb18030 chars can handle invalid chars
262+
CREATE TABLE t1 (a int) ENGINE=InnoDB;
263+
--error ER_INVALID_CHARACTER_STRING
264+
LOAD DATA INFILE '../../std_data/bug21542698.dat' INTO TABLE t1 CHARACTER SET gb18030;
265+
DROP TABLE t1;
266+
261267
DROP DATABASE gb18030;
262268
SET sql_mode = default;
263269
--echo #

sql/sql_load.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,10 +1568,11 @@ READ_INFO::~READ_INFO()
15681568
if (chr1 != my_b_EOF) \
15691569
{ \
15701570
len= my_mbcharlen_2((cs), (chr), chr1); \
1571-
/* Must be gb18030 charset */ \
1572-
DBUG_ASSERT(len == 2 || len == 4); \
1571+
/* Character is gb18030 or invalid (len = 0) */ \
1572+
DBUG_ASSERT(len == 0 || len == 2 || len == 4); \
15731573
} \
1574-
PUSH(chr1); \
1574+
if (len != 0) \
1575+
PUSH(chr1); \
15751576
} \
15761577
} while (0)
15771578

0 commit comments

Comments
 (0)