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)

357359

if link > self._data_len:

358360

raise IncomingDecodeError(

359361

f"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

362364

raise IncomingDecodeError(

363365

f"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:

366368

raise IncomingDecodeError(

367369

f"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)

370372

if not linked_labels:

371-

seen_pointers.add(link)

373+

linked_labels = []

374+

seen_pointers.add(lint_int)

372375

self._decode_labels_at_offset(link, linked_labels, seen_pointers)

373-

self.name_cache[link] = linked_labels

376+

self.name_cache[lint_int] = linked_labels

374377

labels.extend(linked_labels)

375378

if len(labels) > MAX_DNS_LABELS:

376379

raise IncomingDecodeError(