Mercurial > hg
comparison mercurial/url.py @ 51992:71658f79758a
clonebundle-digest: add recursion guards for Python 3.8
For Python 3.8 and 3.9, the read/readinto pair can recurse, so make sure
the data is only hashed once.
author | Joerg Sonnenberger <joerg@bec.de> |
---|---|
date | Fri, 11 Oct 2024 14:37:59 +0200 |
parents | aa7f4a45d8fa |
children |
comparison
equal
deleted
inserted
replaced
51991:f0bee30af890 | 51992:71658f79758a |
---|---|
536 self._digest_consumed, | 536 self._digest_consumed, |
537 ) | 537 ) |
538 ) | 538 ) |
539 | 539 |
540 def read(self, amt=None): | 540 def read(self, amt=None): |
541 self._digest_recursion_level += 1 | |
541 data = super().read(amt) | 542 data = super().read(amt) |
542 self._digest_input(data) | 543 self._digest_recursion_level -= 1 |
544 if self._digest_recursion_level == 0: | |
545 self._digest_input(data) | |
543 return data | 546 return data |
544 | 547 |
545 def readline(self): | 548 def readline(self): |
549 self._digest_recursion_level += 1 | |
546 data = super().readline() | 550 data = super().readline() |
547 self._digest_input(data) | 551 self._digest_recursion_level -= 1 |
552 if self._digest_recursion_level == 0: | |
553 self._digest_input(data) | |
548 return data | 554 return data |
549 | 555 |
550 def readinto(self, dest): | 556 def readinto(self, dest): |
557 self._digest_recursion_level += 1 | |
551 got = super().readinto(dest) | 558 got = super().readinto(dest) |
552 self._digest_input(dest[:got]) | 559 self._digest_recursion_level -= 1 |
560 if self._digest_recursion_level == 0: | |
561 self._digest_input(dest[:got]) | |
553 return got | 562 return got |
554 | 563 |
555 def _close_conn(self): | 564 def _close_conn(self): |
556 self._digest_finished = True | 565 self._digest_finished = True |
557 return super().close() | 566 return super().close() |
558 | 567 |
559 response.__class__ = digestresponse | 568 response.__class__ = digestresponse |
560 response._digest = self._digest | 569 response._digest = self._digest |
561 response._digest_consumed = 0 | 570 response._digest_consumed = 0 |
562 response._hasher = self._hasher.copy() | 571 response._hasher = self._hasher.copy() |
572 # Python 3.8 / 3.9 recurses internally between read/readinto. | |
573 response._digest_recursion_level = 0 | |
563 response._digest_finished = False | 574 response._digest_finished = False |
564 return response | 575 return response |
565 | 576 |
566 https_response = http_response | 577 https_response = http_response |
567 | 578 |