Skip to content

Commit

Permalink
Fix deserialization of long string field values that are not utf-8.
Browse files Browse the repository at this point in the history
AMQP 0.9.1 allows arbitrary data in long string fields.  However,
py-amqp assumed that the fields would always contain valid utf-8
data and would fail to deserialize messages with a property that
contained non-utf-8 data.

See #323
  • Loading branch information
timburke authored and auvipy committed May 30, 2020
1 parent 5f03457 commit fca0a94
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion amqp/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ def _read_item(buf, offset):
if ftype == 'S':
slen, = unpack_from('>I', buf, offset)
offset += 4
val = pstr_t(buf[offset:offset + slen])
try:
val = pstr_t(buf[offset:offset + slen])
except UnicodeDecodeError:
val = buf[offset:offset + slen]

offset += slen
# 's': short string
elif ftype == 's':
Expand Down
1 change: 1 addition & 0 deletions t/unit/test_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class test_serialization:

@pytest.mark.parametrize('descr,frame,expected,cast', [
('S', b's8thequick', 'thequick', None),
('S', b'S\x00\x00\x00\x03\xc0\xc0\x00', b'\xc0\xc0\x00', None),
('x', b'x\x00\x00\x00\x09thequick\xffIGNORED', b'thequick\xff', None),
('b', b'b' + pack('>B', True), True, None),
('B', b'B' + pack('>b', 123), 123, None),
Expand Down

0 comments on commit fca0a94

Please sign in to comment.