Skip to content

Commit 21a708f

Browse files
committed
Fix BUG96280
1 parent b034f25 commit 21a708f

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

lib/mysql/connector/protocol.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,18 @@ def _parse_binary_values(self, fields, packet, charset='utf-8'):
475475
elif field[1] == FieldType.TIME:
476476
(packet, value) = self._parse_binary_time(packet, field)
477477
values.append(value)
478+
elif field[1] in (FieldType.BLOB, FieldType.TINY_BLOB,
479+
FieldType.MEDIUM_BLOB, FieldType.LONG_BLOB):
480+
## Fix
481+
# - BUG96280
482+
(packet, value) = utils.read_lc_string(packet)
483+
values.append(value)
478484
else:
479485
(packet, value) = utils.read_lc_string(packet)
480-
values.append(value.decode(charset))
486+
try:
487+
values.append(value.decode(charset))
488+
except UnicodeDecodeError:
489+
values.append(value)
481490

482491
return tuple(values)
483492

tests/test_protocol.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,12 +402,16 @@ def test__parse_binary_values(self):
402402
('aDate', 10, None, None, None, None, 1, 128),
403403
('aDateTime', 12, None, None, None, None, 1, 128),
404404
('aTime', 11, None, None, None, None, 1, 128),
405-
('aNull', 6, None, None, None, None, 1, 128)]
405+
('aNull', 6, None, None, None, None, 1, 128),
406+
('aBlob', 252, None, None, None, None, 1, 144),
407+
('aVarBinary', 253, None, None, None, None, 1, 128)]
406408

407409
packet = bytearray(b'\x00\x01\x03\x61\x62\x63\x04\x33\x2e\x31\x34\x08'
408410
b'\x2d\x33\x2e\x31\x34\x31\x35\x39\x04\xd3\x07'
409411
b'\x01\x1f\x07\xb9\x07\x06\x0e\x15\x21\x0e\x0c'
410-
b'\x00\x0a\x00\x00\x00\x10\x0f\x1e\x70\x82\x03\x00')
412+
b'\x00\x0a\x00\x00\x00\x10\x0f\x1e\x70\x82\x03\x00'
413+
b'\x05\xaa\xbb\xcc\xdd\xff'
414+
b'\x05\xaa\xbb\xcc\xdd\xff')
411415

412416
# float/double are returned as DECIMAL by MySQL
413417
exp = ('abc',
@@ -416,7 +420,9 @@ def test__parse_binary_values(self):
416420
datetime.date(2003, 1, 31),
417421
datetime.datetime(1977, 6, 14, 21, 33, 14),
418422
datetime.timedelta(10, 58530, 230000),
419-
None)
423+
None,
424+
bytearray(b'\xaa\xbb\xcc\xdd\xff'),
425+
bytearray(b'\xaa\xbb\xcc\xdd\xff'))
420426
res = self._protocol._parse_binary_values(fields, packet)
421427
self.assertEqual(exp, res)
422428

0 commit comments

Comments
 (0)