From: Date: October 10 2008 10:28pm Subject: bzr commit into mysql-5.1 branch (davi:2772) Bug#37075 List-Archive: http://lists.mysql.com/commits/56058 X-Bug: 37075 Message-Id: <20081010202851.1D96EEC418@skynet.ctb.virtua.com.br> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit # At a local mysql-5.1 repository of davi 2772 Davi Arnaut 2008-10-10 Bug#37075: offset of limit clause might be truncated to 0 on 32-bits server w/o big tables The problem is that the offset argument of the limit clause might be truncated to 0 on 32-bits server built without big tables support. The truncation was happening because the original 64-bits long argument was being cast to a 32-bits (ha_rows) offset counter. The solution is to check if the conversing resulted in value truncation and if so, the offset is set to the maximum possible value that can fit on the type. modified: mysql-test/r/limit.result mysql-test/t/limit.test sql/sql_lex.cc per-file messages: mysql-test/r/limit.result Add test case result for Bug#37075 mysql-test/t/limit.test Add test case for Bug#37075 sql/sql_lex.cc Check for truncation of the offset value. If value was truncated, set to the maximum possible value. === modified file 'mysql-test/r/limit.result' --- a/mysql-test/r/limit.result 2008-02-28 14:34:08 +0000 +++ b/mysql-test/r/limit.result 2008-10-10 20:28:40 +0000 @@ -111,3 +111,6 @@ set @a=-14632475938453979136; execute s using @a, @a; ERROR HY000: Incorrect arguments to EXECUTE End of 5.0 tests +select 1 as a limit 4294967296,10; +a +End of 5.1 tests === modified file 'mysql-test/t/limit.test' --- a/mysql-test/t/limit.test 2008-02-28 23:22:50 +0000 +++ b/mysql-test/t/limit.test 2008-10-10 20:28:40 +0000 @@ -95,3 +95,11 @@ set @a=-14632475938453979136; execute s using @a, @a; --echo End of 5.0 tests + +# +# Bug#37075: offset of limit clause might be truncated to 0 on 32-bits server w/o big tables +# + +select 1 as a limit 4294967296,10; + +--echo End of 5.1 tests === modified file 'sql/sql_lex.cc' --- a/sql/sql_lex.cc 2008-09-18 08:38:44 +0000 +++ b/sql/sql_lex.cc 2008-10-10 20:28:40 +0000 @@ -2403,8 +2403,13 @@ void st_select_lex_unit::set_limit(st_se if (val != (ulonglong)select_limit_val) select_limit_val= HA_POS_ERROR; #endif - offset_limit_cnt= (ha_rows)(sl->offset_limit ? sl->offset_limit->val_uint() : - ULL(0)); + val= sl->offset_limit ? sl->offset_limit->val_uint() : ULL(0); + offset_limit_cnt= (ha_rows)val; +#ifndef BIG_TABLES + /* Check for truncation. */ + if (val != (ulonglong)offset_limit_cnt) + offset_limit_cnt= HA_POS_ERROR; +#endif select_limit_cnt= select_limit_val + offset_limit_cnt; if (select_limit_cnt < select_limit_val) select_limit_cnt= HA_POS_ERROR; // no limit