Skip to content

Commit 93f8959

Browse files
committed
Fix read_len_prefixed_{bytes|str}() to support 0-length sequences
1 parent aca615c commit 93f8959

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

buffer.pyx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,8 @@ cdef class ReadBuffer:
396396
if size < 0:
397397
raise exceptions.BufferError(
398398
'negative length for a len-prefixed bytes value')
399+
if size == 0:
400+
return b''
399401
return self.read_bytes(size)
400402

401403
cdef str read_len_prefixed_utf8(self):
@@ -408,6 +410,9 @@ cdef class ReadBuffer:
408410
raise exceptions.BufferError(
409411
'negative length for a len-prefixed bytes value')
410412

413+
if size == 0:
414+
return ''
415+
411416
self._ensure_first_buf()
412417
cbuf = self._try_read_bytes(size)
413418
if cbuf != NULL:

0 commit comments

Comments
 (0)