diff --git a/bumble/att.py b/bumble/att.py index 07ebe86..49c3130 100644 --- a/bumble/att.py +++ b/bumble/att.py @@ -249,6 +249,8 @@ class ATT_PDU: @classmethod def from_bytes(cls, pdu: bytes) -> ATT_PDU: + if not pdu: + raise ValueError("Empty ATT PDU") op_code = pdu[0] subclass = ATT_PDU.pdu_classes.get(op_code) diff --git a/bumble/hfp.py b/bumble/hfp.py index 7056517..6b8fbb0 100644 --- a/bumble/hfp.py +++ b/bumble/hfp.py @@ -84,12 +84,15 @@ class HfpProtocol: def feed(self, data: bytes | str) -> None: # Convert the data to a string if needed if isinstance(data, bytes): - data = data.decode('utf-8') + data = data.decode('utf-8', errors='replace') logger.debug(f'<<< Data received: {data}') # Add to the buffer and look for lines self.buffer += data + if len(self.buffer) > 65536: + logger.warning("HFP buffer overflow, truncating") + self.buffer = self.buffer[-65536:] while (separator := self.buffer.find('\r')) >= 0: line = self.buffer[:separator].strip() self.buffer = self.buffer[separator + 1 :] diff --git a/bumble/smp.py b/bumble/smp.py index 0f40094..da1c771 100644 --- a/bumble/smp.py +++ b/bumble/smp.py @@ -215,6 +215,8 @@ class SMP_Command: @classmethod def from_bytes(cls, pdu: bytes) -> SMP_Command: + if not pdu: + raise ValueError("Empty SMP PDU") code = CommandCode(pdu[0]) subclass = SMP_Command.smp_classes.get(code)