* Ramil Kalimullin <ramil@stripped> [09/01/12 14:34]:
> 2728 Ramil Kalimullin 2009-01-12
> Fix for bug#19829:make test Failed in mysql_client_test
> *with --with-charset=utf8*
>
> Problem: wrong LONG BLOB field length is sent to a client
> when multibyte server character set used.
I gather the bug happens with LONG TEXT columns, not LONG BLOB.
It's just that both LONG TEXT and LONG BLOB happen to have the
same type code.
When one has a LONG TEXT column with a single-byte
character set, and the connection character set is multi-byte, the
client may get fields longer than UINT_MAX32, due to
<character set column> -> <character set connection> conversion.
In that case column max length does not fit into the 4 bytes
reserved for it in the protocol.
If you agree with my analysis, please add it to the code comment (below).
> - uint max_char_len;
> + ulonglong max_length;
IMHO the old name max_char_len was more descriptive.
> + uint32 field_length;
> int2store(pos, thd_charset->number);
> /*
> For TEXT/BLOB columns, field_length describes the maximum data
> @@ -627,12 +628,17 @@ bool Protocol::send_fields(List<Item> *l
> char_count * mbmaxlen, where character count is taken from the
> definition of the column. In other words, the maximum number
> of characters here is limited by the column definition.
> +
> + Note: the length is limited to UINT_MAX32 as we use 4 bytes
> + to store it.
> */
> - max_char_len= (field.type >= (int) MYSQL_TYPE_TINY_BLOB &&
> - field.type <= (int) MYSQL_TYPE_BLOB) ?
> - field.length / item->collation.collation->mbminlen :
> - field.length / item->collation.collation->mbmaxlen;
> - int4store(pos+2, max_char_len * thd_charset->mbmaxlen);
> + max_length= (field.type >= MYSQL_TYPE_TINY_BLOB &&
> + field.type <= MYSQL_TYPE_BLOB) ?
> + field.length / item->collation.collation->mbminlen :
> + field.length / item->collation.collation->mbmaxlen;
> + max_length*= thd_charset->mbmaxlen;
> + field_length= (max_length > UINT_MAX32) ? UINT_MAX32 : max_length;
> + int4store(pos + 2, field_length);
The patch is OK to push.
--