Skip to content

Commit c956f3a

Browse files
author
Geert Vanderkelen
committed
Merge branch 'issue/BUG20462427' into develop
2 parents 7f103ac + 7221b81 commit c956f3a

File tree

4 files changed

+69
-14
lines changed

4 files changed

+69
-14
lines changed

lib/mysql/connector/network.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# MySQL Connector/Python - MySQL driver written in Python.
2-
# Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
33

44
# MySQL Connector/Python is licensed under the terms of the GPLv2
55
# <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -221,11 +221,13 @@ def recv_plain(self):
221221
try:
222222
# Read the header of the MySQL packet, 4 bytes
223223
packet = bytearray(b'')
224-
while len(packet) < 4:
225-
chunk = self.sock.recv(4)
224+
packet_len = 0
225+
while packet_len < 4:
226+
chunk = self.sock.recv(4 - packet_len)
226227
if not chunk:
227228
raise errors.InterfaceError(errno=2013)
228229
packet += chunk
230+
packet_len = len(packet)
229231

230232
# Save the packet number and payload length
231233
self._packet_number = packet[3]
@@ -257,12 +259,13 @@ def recv_py26_plain(self):
257259
try:
258260
# Read the header of the MySQL packet, 4 bytes
259261
header = bytearray(b'')
260-
261-
while len(header) < 4:
262-
chunk = self.sock.recv(4)
262+
header_len = 0
263+
while header_len < 4:
264+
chunk = self.sock.recv(4 - header_len)
263265
if not chunk:
264266
raise errors.InterfaceError(errno=2013)
265267
header += chunk
268+
header_len = len(header)
266269

267270
# Save the packet number and payload length
268271
self._packet_number = header[3]

lib/mysql/connector/protocol.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# MySQL Connector/Python - MySQL driver written in Python.
2-
# Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
33

44
# MySQL Connector/Python is licensed under the terms of the GPLv2
55
# <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -320,11 +320,8 @@ def read_text_result(self, sock, count=1):
320320
while packet.startswith(b'\xff\xff\xff'):
321321
datas.append(packet[4:])
322322
packet = sock.recv()
323-
if packet[4] == 254:
324-
eof = self.parse_eof(packet)
325-
else:
326-
datas.append(packet[4:])
327-
rowdata = utils.read_lc_string_list(b''.join(datas))
323+
datas.append(packet[4:])
324+
rowdata = utils.read_lc_string_list(bytearray(b'').join(datas))
328325
elif packet[4] == 254:
329326
eof = self.parse_eof(packet)
330327
rowdata = None

tests/test_bugs.py

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3240,7 +3240,6 @@ def tearDown(self):
32403240
self.cnx.close()
32413241

32423242

3243-
32443243
class BugOra19777815(tests.MySQLConnectorTests):
32453244
"""BUG#19777815: CALLPROC() DOES NOT SUPPORT WARNINGS
32463245
"""
@@ -3289,7 +3288,11 @@ def test_warning_with_rows(self):
32893288
cur.callproc(self.sp2)
32903289

32913290
exp = [(1,)]
3292-
self.assertEqual(exp, cur.stored_results().next().fetchall())
3291+
if PY2:
3292+
self.assertEqual(exp, cur.stored_results().next().fetchall())
3293+
else:
3294+
self.assertEqual(exp, next(cur.stored_results()).fetchall())
3295+
32933296
exp = [(u'Warning', 1642, u'TEST WARNING')]
32943297
self.assertEqual(exp, cur.fetchwarnings())
32953298

@@ -3381,3 +3384,53 @@ def test_set(self):
33813384

33823385
cur.execute("SELECT * FROM {0}".format(self.tbl))
33833386
self.assertEqual(exp, cur.fetchall())
3387+
3388+
3389+
class BugOra20462427(tests.MySQLConnectorTests):
3390+
"""BUG#20462427: BYTEARRAY INDEX OUT OF RANGE
3391+
"""
3392+
def setUp(self):
3393+
config = tests.get_mysql_config()
3394+
config['autocommit'] = True
3395+
config['connection_timeout'] = 100
3396+
self.cnx = connection.MySQLConnection(**config)
3397+
self.cur = self.cnx.cursor()
3398+
3399+
self.tbl = 'BugOra20462427'
3400+
self.cur.execute("DROP TABLE IF EXISTS {0}".format(self.tbl))
3401+
3402+
create = ("CREATE TABLE {0} ("
3403+
"id INT PRIMARY KEY, "
3404+
"a LONGTEXT "
3405+
") ENGINE=Innodb DEFAULT CHARSET utf8".format(self.tbl))
3406+
3407+
self.cur.execute(create)
3408+
3409+
def tearDown(self):
3410+
self.cur.execute("DROP TABLE IF EXISTS {0}".format(self.tbl))
3411+
self.cur.close()
3412+
self.cnx.close()
3413+
3414+
def test_bigdata(self):
3415+
temp = 'a'*16777210
3416+
insert = "INSERT INTO {0} (a) VALUES ('{1}')".format(self.tbl, temp)
3417+
3418+
self.cur.execute(insert)
3419+
self.cur.execute("SELECT a FROM {0}".format(self.tbl))
3420+
res = self.cur.fetchall()
3421+
self.assertEqual(16777210, len(res[0][0]))
3422+
3423+
self.cur.execute("UPDATE {0} SET a = concat(a, 'a')".format(self.tbl))
3424+
self.cur.execute("SELECT a FROM {0}".format(self.tbl))
3425+
res = self.cur.fetchall()
3426+
self.assertEqual(16777211, len(res[0][0]))
3427+
3428+
self.cur.execute("UPDATE {0} SET a = concat(a, 'a')".format(self.tbl))
3429+
self.cur.execute("SELECT a FROM {0}".format(self.tbl))
3430+
res = self.cur.fetchall()
3431+
self.assertEqual(16777212, len(res[0][0]))
3432+
3433+
self.cur.execute("UPDATE {0} SET a = concat(a, 'a')".format(self.tbl))
3434+
self.cur.execute("SELECT a FROM {0}".format(self.tbl))
3435+
res = self.cur.fetchall()
3436+
self.assertEqual(16777213, len(res[0][0]))

unittests.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
language = {lc_messages_dir}/english
121121
122122
[mysqld]
123+
max_allowed_packet=26777216
123124
basedir = {basedir}
124125
datadir = {datadir}
125126
tmpdir = {tmpdir}
@@ -135,6 +136,7 @@
135136
log-bin = mysqld_{name}_bin
136137
local_infile = 1
137138
innodb_flush_log_at_trx_commit = 2
139+
innodb_log_file_size = 1Gb
138140
general_log_file = general_{name}.log
139141
ssl
140142
"""

0 commit comments

Comments
 (0)