From 4b8fd23d10bf1aa551e943e211514c572845e9f3 Mon Sep 17 00:00:00 2001 From: setrofim Date: Thu, 18 Apr 2019 13:14:42 +0100 Subject: [PATCH] Add missing check for zero length bytes string. Add a missing check for a zero length bytes string inside loads() and raise a ValueError in that case. Previously, the empty string was allowed to propagate, resulting in an EOFError shortly down the line. This is inconsistent with the C implementation that raises a ValueError. --- cbor/cbor.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cbor/cbor.py b/cbor/cbor.py index 2dfffb5..d17ac14 100644 --- a/cbor/cbor.py +++ b/cbor/cbor.py @@ -260,6 +260,8 @@ def loads(data): """ if data is None: raise ValueError("got None for buffer to decode in loads") + elif data == b'': + raise ValueError("got zero length string loads") fp = StringIO(data) return _loads(fp)[0]