feat: speed up incoming data parser (#1161) · python-zeroconf/python-zeroconf@cb4c3b2
@@ -353,7 +353,9 @@ def _decode_labels_at_offset(self, off: int, labels: List[str], seen_pointers: S
353353 )
354354355355# We have a DNS compression pointer
356-link = (length & 0x3F) * 256 + self.data[off + 1]
356+link_data = self.data[off + 1]
357+link = (length & 0x3F) * 256 + link_data
358+lint_int = int(link)
357359if link > self._data_len:
358360raise IncomingDecodeError(
359361f"DNS compression pointer at {off} points to {link} beyond packet from {self.source}"
@@ -362,15 +364,16 @@ def _decode_labels_at_offset(self, off: int, labels: List[str], seen_pointers: S
362364raise IncomingDecodeError(
363365f"DNS compression pointer at {off} points to itself from {self.source}"
364366 )
365-if link in seen_pointers:
367+if lint_int in seen_pointers:
366368raise IncomingDecodeError(
367369f"DNS compression pointer at {off} was seen again from {self.source}"
368370 )
369-linked_labels = self.name_cache.get(link, [])
371+linked_labels = self.name_cache.get(lint_int)
370372if not linked_labels:
371-seen_pointers.add(link)
373+linked_labels = []
374+seen_pointers.add(lint_int)
372375self._decode_labels_at_offset(link, linked_labels, seen_pointers)
373-self.name_cache[link] = linked_labels
376+self.name_cache[lint_int] = linked_labels
374377labels.extend(linked_labels)
375378if len(labels) > MAX_DNS_LABELS:
376379raise IncomingDecodeError(