One function
NetstringSocket in mahmoud/boltons
The author described this change as “Fix NetstringSocket to correctly use arguments to .read_ns() method.”. It counts as a record because the check below fails on the code as it stood at 81e44a231 and passes on 0a20b37cc, with nothing else changed between the two runs.
Projectmahmoud/boltons
Fix saved2020-03-28
Sharing licenceBSD-2-Clause · LICENSE
Change size+14 −5
What the code was meant to do, written into the code itself as a docstring
Reads and writes using the netstring protocol. More info: https://en.wikipedia.org/wiki/Netstring Even more info: http://cr.yp.to/proto/netstrings.txt
The change
| 19 | 19 | ||
| 20 | 20 | def setmaxsize(self, maxsize): | |
| 21 | 21 | self.maxsize = maxsize | |
| 22 | - | self._msgsize_maxsize = len(str(maxsize)) + 1 # len(str()) == log10 | |
| 22 | + | self._msgsize_maxsize = self._calc_msgsize_maxsize(maxsize) | |
| 23 | 23 | ||
| 24 | + | def _calc_msgsize_maxsize(self, maxsize): | |
| 25 | + | return len(str(maxsize)) + 1 # len(str()) == log10 | |
| 26 | + | ||
| 24 | 27 | def read_ns(self, timeout=_UNSET, maxsize=_UNSET): | |
| 25 | 28 | if timeout is _UNSET: | |
| 26 | 29 | timeout = self.timeout | |
| 27 | 30 | ||
| 31 | + | if maxsize is _UNSET: | |
| 32 | + | maxsize = self.maxsize | |
| 33 | + | msgsize_maxsize = self._msgsize_maxsize | |
| 34 | + | else: | |
| 35 | + | msgsize_maxsize = self._calc_msgsize_maxsize(maxsize) | |
| 36 | + | ||
| 28 | 37 | size_prefix = self.bsock.recv_until(b':', | |
| 29 | - | timeout=self.timeout, | |
| 30 | - | maxsize=self._msgsize_maxsize) | |
| 38 | + | timeout=timeout, | |
| 39 | + | maxsize=msgsize_maxsize) | |
| 31 | 40 | try: | |
| 32 | 41 | size = int(size_prefix) | |
| 33 | 42 | except ValueError: | |
| 34 | 43 | raise NetstringInvalidSize('netstring message size must be valid' | |
| 35 | 44 | ' integer, not %r' % size_prefix) | |
| 36 | 45 | ||
| 37 | - | if size > self.maxsize: | |
| 38 | - | raise NetstringMessageTooLong(size, self.maxsize) | |
| 46 | + | if size > maxsize: | |
| 47 | + | raise NetstringMessageTooLong(size, maxsize) | |
| 39 | 48 | payload = self.bsock.recv_size(size) | |
| 40 | 49 | if self.bsock.recv(1) != b',': | |
| 41 | 50 | raise NetstringProtocolError("expected trailing ',' after message") |
The check that tells the two apart
fail→pass·tests/test_socketutils.py::test_socketutils_netstring_timeout
Check file tests/test_socketutils.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before it81e44a2319ce0bef0de44f1059762b97879cb35d
Broken version dated2020-03-23
Moduleboltons.socketutils
Units changedNetstringSocket
Fingerprint5eeb36aac33ef446
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.
Other bugs found in mahmoud/boltons
- 2026-08-06Bits
- 2026-08-06JSONLIterator
- 2026-08-06tableutils: fix Table.to_text crashes on degenerate tables and headers
- 2026-07-18backoff_iter
- 2026-07-17singularize
- 2026-07-17fix(fileutils): accept os.PathLike in AtomicSaver