Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

Re: bk commit into 5.0 tree (cmiller:1.2500) BUG#15776

From: Timothy Smith <tim(at)mysql.com>
Date: Fri Aug 10 2007 - 16:05:56 EDT


Chad,

> ChangeSet@1.2500, 2007-08-06 15:05:04-04:00, cmiller@zippy.cornsilk.net +7 -0
> Bug#15776: 32-bit signed int used for length of blob
>
> Contributed patch from Martin Friebe, CLA from 2007-02-24.
>

<cut>

> diff -Nrup a/mysql-test/t/type_blob.test b/mysql-test/t/type_blob.test
> --- a/mysql-test/t/type_blob.test 2007-02-14 08:44:31 -05:00
> +++ b/mysql-test/t/type_blob.test 2007-08-06 15:05:01 -04:00
> @@ -436,4 +436,94 @@ set @@sql_mode='TRADITIONAL';
> create table t1 (a text default '');
> set @@sql_mode='';
>
> +#
> +# Bug#15776: 32-bit signed int used for length of blob
> +# """LONGBLOB: A BLOB column with a maximum length of 4,294,967,295 or 4GB."""
> +#
> +create table b15776 (data blob(2147483647));
> +drop table b15776;
> +--error ER_PARSE_ERROR
> +create table b15776 (data blob(-1));
> +create table b15776 (data blob(2147483648));
> +drop table b15776;
> +create table b15776 (data blob(4294967294));
> +drop table b15776;
> +create table b15776 (data blob(4294967295));
> +--error ER_TOO_BIG_FIELDLENGTH
> +create table b15776 (data blob(4294967296));
> +
> +CREATE TABLE t1 (a blob(2147483647), b blob(2147483648), c blob(4294967295), a1 text(2147483647), b1 text(2147483648), c1 text(4294967295) );
> +show columns from t1;
> +drop table t1;
> +--error ER_TOO_BIG_FIELDLENGTH
> +CREATE TABLE t1 (a blob(4294967296));
> +--error ER_TOO_BIG_FIELDLENGTH
> +CREATE TABLE t1 (a text(4294967296));
> +--error ER_TOO_BIG_FIELDLENGTH
> +CREATE TABLE t1 (a blob(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
> +--error ER_TOO_BIG_FIELDLENGTH
> +CREATE TABLE t1 (a text(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
> +
> +# BUG #15776: additional test, affecting other functions
> +--error ER_TOO_BIG_DISPLAYWIDTH
> +CREATE TABLE t1 (a int(4294967296));
> +--error 1064

I'd prefer to use ER_PARSE_ERROR consistently.

> +CREATE TABLE t1 (a char(4294967296));
> +CREATE TABLE t1 (a year(4294967296));

Might want a comment here, saying that YEAR() currently accepting any length is probably a bug.

> +show columns from t1;
> +drop table t1;
> +--error ER_TOO_BIG_DISPLAYWIDTH
> +CREATE TABLE t1 (a timestamp(4294967296));
> +
> +--error ER_TOO_BIG_DISPLAYWIDTH
> +CREATE TABLE t1 (a int(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
> +--error 1064
> +CREATE TABLE t1 (a char(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
> +CREATE TABLE t1 (a year(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
> +show columns from t1;
> +drop table t1;
> +--error ER_TOO_BIG_DISPLAYWIDTH
> +CREATE TABLE t1 (a timestamp(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
> +
> +# do not select, to much memory needed

Do you need help?X

"too" :-)

> +CREATE TABLE t1 select cast(null as char(4294967295));
> +show columns from t1;
> +drop table t1;
> +CREATE TABLE t1 select cast(null as nchar(4294967295));
> +show columns from t1;
> +drop table t1;
> +CREATE TABLE t1 select cast(null as binary(4294967295));
> +show columns from t1;
> +drop table t1;
> +
> +explain select cast(1 as char(4294967295));
> +explain select cast(1 as nchar(4294967295));
> +explain select cast(1 as binary(4294967295));
> +
> +--error 1074

Similarly, I'd prefer ER_TOO_BIG_FIELDLENGTH here.

> +explain select cast(1 as char(4294967296));
> +--error 1074
> +explain select cast(1 as char(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
> +--error 1074
> +explain select cast(1 as nchar(4294967296));
> +--error 1074
> +explain select cast(1 as nchar(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
> +--error 1074
> +explain select cast(1 as binary(4294967296));
> +--error 1074
> +explain select cast(1 as binary(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
> +
> +--error 1074
> +explain select convert(1, char(4294967296));
> +--error 1074
> +explain select convert(1, char(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
> +--error 1074
> +explain select convert(1, nchar(4294967296));
> +--error 1074
> +explain select convert(1, nchar(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
> +--error 1074
> +explain select convert(1, binary(4294967296));
> +--error 1074
> +explain select convert(1, binary(999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999));
> +
> --echo End of 5.0 tests
> diff -Nrup a/sql/field.cc b/sql/field.cc
> --- a/sql/field.cc 2007-07-25 18:28:50 -04:00
> +++ b/sql/field.cc 2007-08-06 15:05:02 -04:00
> @@ -8395,8 +8395,15 @@ bool create_field::init(THD *thd, char *
> (fld_type_modifier & NOT_NULL_FLAG) && fld_type != FIELD_TYPE_TIMESTAMP)
> flags|= NO_DEFAULT_VALUE_FLAG;
>
> - if (fld_length && !(length= (uint) atoi(fld_length)))
> - fld_length= 0; /* purecov: inspected */
> + errno= 0;
> + if (fld_length != 0)
> + {
> + length= strtoul(fld_length, NULL, 10);
> + if (length == 0)
> + fld_length= 0; /* purecov: inspected */
> + }
> + bool err_too_long= (errno != 0);
> +
> sign_len= fld_type_modifier & UNSIGNED_FLAG ? 0 : 1;
>
> switch (fld_type) {
> @@ -8677,6 +8684,12 @@ bool create_field::init(THD *thd, char *
> fld_name, max_field_charlength); /* purecov: inspected */
> DBUG_RETURN(TRUE);
> }
> + else if ((flags & BLOB_FLAG) && err_too_long)
> + {
> + my_error(ER_TOO_BIG_FIELDLENGTH, MYF(0), fld_name, UINT_MAX);

I think I'd #define MAX_FIELD_BLOBLENGTH UINT_MAX in sql/unireg.h, and use that here (and below).

> + DBUG_RETURN(TRUE);
> + }
> +

I'd put this up in the switch statement itself. There's only one place where BLOB_FLAG is set - I think this would fit more cleanly in that spot.

> fld_type_modifier&= AUTO_INCREMENT_FLAG;
> if ((~allowed_type_modifier) & fld_type_modifier)
> {
> diff -Nrup a/sql/item_create.cc b/sql/item_create.cc
> --- a/sql/item_create.cc 2007-08-02 05:51:00 -04:00
> +++ b/sql/item_create.cc 2007-08-06 15:05:02 -04:00
> @@ -451,7 +451,7 @@ Item *create_func_cast(Item *a, Cast_tar
> const char *c_len, const char *c_dec,
> CHARSET_INFO *cs)
> {
> - Item *res;
> + Item *res= NULL;
> ulong len;
> uint dec;
> LINT_INIT(res);
> @@ -487,9 +487,16 @@ Item *create_func_cast(Item *a, Cast_tar
> res= new Item_decimal_typecast(a, len, dec);
> break;
> case ITEM_CAST_CHAR:
> - len= c_len ? atoi(c_len) : -1;
> + errno= 0;
> + longlong len= c_len ? strtoul(c_len, NULL, 10) : -1LL;

Do you need more help?X

LL(-1)

> + if (errno != 0)
> + {
> + my_error(ER_TOO_BIG_FIELDLENGTH, MYF(0), "cast as char", UINT_MAX);
> + break;

I'd probably just return 0 here, and skip the res= NULL above.

> + }
> +
> res= new Item_char_typecast(a, len, cs ? cs :
> - current_thd->variables.collation_connection);
> + current_thd->variables.collation_connection);
> break;
> }
> return res;

<cut>

Regards,

Timothy

-- 
-- Timothy Smith       Team Lead, Maintenance; Dolores, Colorado, USA
-- MySQL, www.mysql.com      The best DATABASE COMPANY in the GALAXY!

-- 
MySQL Code Commits Mailing List
For list archives: 
http://lists.mysql.com/commits
To unsubscribe:    
http://lists.mysql.com/commits?unsub=lists@pantek.com
Received on Fri Aug 10 16:08:33 2007

This archive was generated by hypermail 2.1.8 : Sun Oct 07 2007 - 08:30:34 EDT

Can we help you?X

Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library