Skip to content

Commit abb670c

Browse files
author
Sujatha Sivakumar
committed
Merge branch 'mysql-5.6' into mysql-5.7
2 parents c2cf243 + ba082ab commit abb670c

File tree

9 files changed

+76
-45
lines changed

9 files changed

+76
-45
lines changed

client/mysqlbinlog.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1616
*/
1717

18-
/*
18+
/*
1919
2020
TODO: print the catalog (some USE catalog.db ????).
2121

include/base64.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -23,22 +23,22 @@ extern "C" {
2323
/*
2424
Calculate how much memory needed for dst of base64_encode()
2525
*/
26-
int base64_needed_encoded_length(int length_of_data);
26+
uint64 base64_needed_encoded_length(uint64 length_of_data);
2727

2828
/*
2929
Maximum length base64_encode_needed_length() can accept with no overflow.
3030
*/
31-
int base64_encode_max_arg_length(void);
31+
uint64 base64_encode_max_arg_length(void);
3232

3333
/*
3434
Calculate how much memory needed for dst of base64_decode()
3535
*/
36-
int base64_needed_decoded_length(int length_of_encoded_data);
36+
uint64 base64_needed_decoded_length(uint64 length_of_encoded_data);
3737

3838
/*
3939
Maximum length base64_decode_needed_length() can accept with no overflow.
4040
*/
41-
int base64_decode_max_arg_length();
41+
uint64 base64_decode_max_arg_length();
4242

4343
/*
4444
Encode data as a base64 string
@@ -48,7 +48,7 @@ int base64_encode(const void *src, size_t src_len, char *dst);
4848
/*
4949
Decode a base64 string into data
5050
*/
51-
int base64_decode(const char *src, size_t src_len,
51+
int64 base64_decode(const char *src, size_t src_len,
5252
void *dst, const char **end_ptr, int flags);
5353

5454
/* Allow multuple chunks 'AAA= AA== AA==', binlog uses this */

mysys/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ TARGET_LINK_LIBRARIES(queues mysys)
8585
SET_TARGET_PROPERTIES(queues PROPERTIES COMPILE_FLAGS "-DMAIN")
8686
ADD_TEST(queues_test queues)
8787

88+
ADD_EXECUTABLE(base64_test base64.c)
89+
SET_TARGET_PROPERTIES(base64_test PROPERTIES COMPILE_FLAGS "-DMAIN")
90+
TARGET_LINK_LIBRARIES(base64_test mysys)
91+
8892
IF(MSVC)
8993
INSTALL_DEBUG_TARGET(mysys DESTINATION ${INSTALL_LIBDIR}/debug)
9094
ENDIF()

mysys/base64.c

+40-21
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -28,15 +28,15 @@ static char base64_table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
2828
* Maximum length base64_needed_encoded_length()
2929
* can handle without overflow.
3030
*/
31-
int
31+
uint64
3232
base64_encode_max_arg_length()
3333
{
34-
#if (SIZEOF_INT == 8)
34+
#if (SIZEOF_VOIDP == 8)
3535
/*
3636
6827690988321067803 -> 9223372036854775805
3737
6827690988321067804 -> -9223372036854775807
3838
*/
39-
return 0x5EC0D4C77B03531BLL
39+
return 0x5EC0D4C77B03531BLL;
4040
#else
4141
/*
4242
1589695686 -> 2147483646
@@ -47,10 +47,11 @@ base64_encode_max_arg_length()
4747
}
4848

4949

50-
int
51-
base64_needed_encoded_length(int length_of_data)
50+
uint64
51+
base64_needed_encoded_length(uint64 length_of_data)
5252
{
53-
int nb_base64_chars;
53+
uint64 nb_base64_chars;
54+
if (length_of_data == 0) return 1;
5455
nb_base64_chars= (length_of_data + 2) / 3 * 4;
5556

5657
return
@@ -64,21 +65,21 @@ base64_needed_encoded_length(int length_of_data)
6465
* Maximum length base64_needed_decoded_length()
6566
* can handle without overflow.
6667
*/
67-
int
68+
uint64
6869
base64_decode_max_arg_length()
6970
{
70-
#if (SIZEOF_INT == 8)
71+
#if (SIZEOF_VOIDP == 8)
7172
return 0x2AAAAAAAAAAAAAAALL;
7273
#else
7374
return 0x2AAAAAAA;
7475
#endif
7576
}
7677

7778

78-
int
79-
base64_needed_decoded_length(int length_of_encoded_data)
79+
uint64
80+
base64_needed_decoded_length(uint64 length_of_encoded_data)
8081
{
81-
return (int) ceil(length_of_encoded_data * 3 / 4);
82+
return (uint64) ceil(length_of_encoded_data * 3 / 4);
8283
}
8384

8485

@@ -313,7 +314,7 @@ my_base64_decoder_getch(MY_BASE64_DECODER *decoder)
313314
* @flags flags e.g. allow multiple chunks
314315
* @return Number of bytes written at 'dst', or -1 in case of failure
315316
*/
316-
int
317+
int64
317318
base64_decode(const char *src_base, size_t len,
318319
void *dst, const char **end_ptr, int flags)
319320
{
@@ -379,16 +380,31 @@ main(void)
379380
size_t k, l;
380381
size_t dst_len;
381382
size_t needed_length;
382-
383-
for (i= 0; i < 500; i++)
383+
char * src;
384+
char * s;
385+
char * str;
386+
char * dst;
387+
const char *end_ptr;
388+
size_t src_len;
389+
390+
for (i= 0; i <= 500; i++)
384391
{
385392
/* Create source data */
386-
const size_t src_len= rand() % 1000 + 1;
393+
if (i == 500)
394+
{
395+
#if (SIZEOF_VOIDP == 8)
396+
printf("Test case for base64 max event length: 2119594243\n");
397+
src_len= 2119594243;
398+
#else
399+
printf("Test case for base64 max event length: 536870912\n");
400+
src_len= 536870912;
401+
#endif
402+
}
403+
else
404+
src_len= rand() % 1000 + 1;
387405

388-
char * src= (char *) malloc(src_len);
389-
char * s= src;
390-
char * str;
391-
char * dst;
406+
src= (char *) malloc(src_len);
407+
s= src;
392408

393409
require(src);
394410
for (j= 0; j<src_len; j++)
@@ -409,7 +425,7 @@ main(void)
409425
/* Decode */
410426
dst= (char *) malloc(base64_needed_decoded_length(strlen(str)));
411427
require(dst);
412-
dst_len= base64_decode(str, strlen(str), dst, NULL);
428+
dst_len= base64_decode(str, strlen(str), dst, &end_ptr, 0);
413429
require(dst_len == src_len);
414430

415431
if (memcmp(src, dst, src_len) != 0)
@@ -437,6 +453,9 @@ main(void)
437453
(uint) src_len, (uint) dst_len);
438454
require(0);
439455
}
456+
free(src);
457+
free(str);
458+
free(dst);
440459
}
441460
printf("Test succeeded.\n");
442461
return 0;

sql/item_strfunc.cc

+7-7
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,7 @@ void Item_func_to_base64::fix_length_and_dec()
13131313
}
13141314
else
13151315
{
1316-
int length= base64_needed_encoded_length((int) args[0]->max_length);
1316+
uint64 length= base64_needed_encoded_length((uint64) args[0]->max_length);
13171317
DBUG_ASSERT(length > 0);
13181318
fix_char_length_ulonglong((ulonglong) length - 1);
13191319
}
@@ -1324,11 +1324,11 @@ String *Item_func_to_base64::val_str_ascii(String *str)
13241324
{
13251325
String *res= args[0]->val_str(str);
13261326
bool too_long= false;
1327-
int length;
1327+
uint64 length;
13281328
if (!res ||
13291329
res->length() > (uint) base64_encode_max_arg_length() ||
13301330
(too_long=
1331-
((uint) (length= base64_needed_encoded_length((int) res->length())) >
1331+
((uint64) (length= base64_needed_encoded_length((uint64) res->length())) >
13321332
current_thd->variables.max_allowed_packet)) ||
13331333
tmp_value.alloc((uint) length))
13341334
{
@@ -1358,7 +1358,7 @@ void Item_func_from_base64::fix_length_and_dec()
13581358
}
13591359
else
13601360
{
1361-
int length= base64_needed_decoded_length((int) args[0]->max_length);
1361+
uint64 length= base64_needed_decoded_length((uint64) args[0]->max_length);
13621362
fix_char_length_ulonglong((ulonglong) length);
13631363
}
13641364
maybe_null= 1; // Can be NULL, e.g. in case of badly formed input string
@@ -1369,16 +1369,16 @@ String *Item_func_from_base64::val_str(String *str)
13691369
{
13701370
String *res= args[0]->val_str_ascii(str);
13711371
bool too_long= false;
1372-
int length;
1372+
int64 length;
13731373
const char *end_ptr;
13741374

13751375
if (!res ||
13761376
res->length() > (uint) base64_decode_max_arg_length() ||
13771377
(too_long=
1378-
((uint) (length= base64_needed_decoded_length((int) res->length())) >
1378+
((uint64) (length= base64_needed_decoded_length((uint64) res->length())) >
13791379
current_thd->variables.max_allowed_packet)) ||
13801380
tmp_value.alloc((uint) length) ||
1381-
(length= base64_decode(res->ptr(), (int) res->length(),
1381+
(length= base64_decode(res->ptr(), (uint64) res->length(),
13821382
(char *) tmp_value.ptr(), &end_ptr, 0)) < 0 ||
13831383
end_ptr < res->ptr() + res->length())
13841384
{

sql/log_event.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2691,7 +2691,7 @@ void Log_event::print_base64(IO_CACHE* file,
26912691
uint32 size= uint4korr(ptr + EVENT_LEN_OFFSET);
26922692
DBUG_ENTER("Log_event::print_base64");
26932693

2694-
size_t const tmp_str_sz= base64_needed_encoded_length((int) size);
2694+
uint64 const tmp_str_sz= base64_needed_encoded_length((uint64) size);
26952695
char *const tmp_str= (char *) my_malloc(key_memory_log_event,
26962696
tmp_str_sz, MYF(MY_WME));
26972697
if (!tmp_str) {

sql/sql_binlog.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,11 @@ void mysql_client_binlog_statement(THD* thd)
185185
strptr < thd->lex->comment.str + thd->lex->comment.length ; )
186186
{
187187
char const *endptr= 0;
188-
int bytes_decoded= base64_decode(strptr, coded_len, buf, &endptr,
188+
int64 bytes_decoded= base64_decode(strptr, coded_len, buf, &endptr,
189189
MY_BASE64_DECODE_ALLOW_MULTIPLE_CHUNKS);
190190

191191
DBUG_PRINT("info",
192-
("bytes_decoded: %d strptr: 0x%lx endptr: 0x%lx ('%c':%d)",
192+
("bytes_decoded: %lld strptr: 0x%lx endptr: 0x%lx ('%c':%d)",
193193
bytes_decoded, (long) strptr, (long) endptr, *endptr,
194194
*endptr));
195195

@@ -217,7 +217,7 @@ void mysql_client_binlog_statement(THD* thd)
217217
order to be able to read exactly what is necessary.
218218
*/
219219

220-
DBUG_PRINT("info",("binlog base64 decoded_len: %lu bytes_decoded: %d",
220+
DBUG_PRINT("info",("binlog base64 decoded_len: %lu bytes_decoded: %lld",
221221
(ulong) decoded_len, bytes_decoded));
222222

223223
/*
@@ -237,7 +237,7 @@ void mysql_client_binlog_statement(THD* thd)
237237
my_error(ER_SYNTAX_ERROR, MYF(0));
238238
goto end;
239239
}
240-
DBUG_PRINT("info", ("event_len=%lu, bytes_decoded=%d",
240+
DBUG_PRINT("info", ("event_len=%lu, bytes_decoded=%lld",
241241
event_len, bytes_decoded));
242242

243243
if (check_event_type(bufptr[EVENT_TYPE_OFFSET], rli))

storage/ndb/src/mgmapi/mgmapi.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -3404,7 +3404,11 @@ ndb_mgm_set_configuration(NdbMgmHandle h, ndb_mgm_configuration *c)
34043404
}
34053405

34063406
BaseString encoded;
3407-
encoded.assfmt("%*s", base64_needed_encoded_length(buf.length()), "Z");
3407+
/*
3408+
The base64 encoded data of BaseString can be of max length (1024*1024)/3*4
3409+
hence using int to store the length.
3410+
*/
3411+
encoded.assfmt("%*s", (int)base64_needed_encoded_length(buf.length()), "Z");
34083412
(void) base64_encode(buf.get_data(), buf.length(), (char*)encoded.c_str());
34093413

34103414
Properties args;

storage/ndb/src/mgmsrv/Config.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -240,9 +240,13 @@ Config::pack64(BaseString& encoded) const
240240
if (m_configValues->m_config.pack(buf) == 0)
241241
return false;
242242

243-
// Expand the string to correct length by filling with Z
243+
/*
244+
Expand the string to correct length by filling with Z.
245+
The base64 encoded data of UtilBuffer can be of max length (1024*1024)/3*4
246+
hence using int to store the length.
247+
*/
244248
encoded.assfmt("%*s",
245-
base64_needed_encoded_length(buf.length()),
249+
(int)base64_needed_encoded_length(buf.length()),
246250
"Z");
247251

248252
if (base64_encode(buf.get_data(),

0 commit comments

Comments
 (0)