|
43 | 43 | logger = logging.getLogger(__name__)
|
44 | 44 |
|
45 | 45 |
|
46 |
| -C_INT_MAX = 256 ** ctypes.sizeof(ctypes.c_int) // 2 - 1 |
| 46 | +# Workaround for OpenSSL 1.0.2. |
| 47 | +# Can drop with OpenSSL 1.1.1 used by Python 3.10+. |
| 48 | +# ref: https://bugs.python.org/issue42853 |
| 49 | +if sys.version_info < (3, 10): |
| 50 | + OPENSSL_MAX_CHUNKSIZE = 256 ** ctypes.sizeof(ctypes.c_int) // 2 - 1 |
| 51 | +else: |
| 52 | + OPENSSL_MAX_CHUNKSIZE = 256 ** ctypes.sizeof(ctypes.c_size_t) - 1 |
| 53 | + |
47 | 54 | MAX_BUFFER_SIZE = MEMORY_LIMIT / 2
|
48 | 55 |
|
49 | 56 |
|
@@ -212,9 +219,9 @@ async def read(self, deserializers=None):
|
212 | 219 | (frames_nbytes,) = struct.unpack(fmt, frames_nbytes)
|
213 | 220 |
|
214 | 221 | frames = host_array(frames_nbytes)
|
215 |
| - # Workaround for OpenSSL 1.0.2 (can drop with OpenSSL 1.1.1) |
216 | 222 | for i, j in sliding_window(
|
217 |
| - 2, range(0, frames_nbytes + C_INT_MAX, C_INT_MAX) |
| 223 | + 2, |
| 224 | + range(0, frames_nbytes + OPENSSL_MAX_CHUNKSIZE, OPENSSL_MAX_CHUNKSIZE), |
218 | 225 | ):
|
219 | 226 | chunk = frames[i:j]
|
220 | 227 | chunk_nbytes = len(chunk)
|
@@ -351,8 +358,7 @@ class TLS(TCP):
|
351 | 358 | A TLS-specific version of TCP.
|
352 | 359 | """
|
353 | 360 |
|
354 |
| - # Workaround for OpenSSL 1.0.2 (can drop with OpenSSL 1.1.1) |
355 |
| - max_shard_size = min(C_INT_MAX, TCP.max_shard_size) |
| 361 | + max_shard_size = min(OPENSSL_MAX_CHUNKSIZE, TCP.max_shard_size) |
356 | 362 |
|
357 | 363 | def _read_extra(self):
|
358 | 364 | TCP._read_extra(self)
|
|
0 commit comments