Skip to content

Commit 836a92a

Browse files
authored
chunking didn't actually work (#5499)
1 parent 085d1e4 commit 836a92a

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/cryptography/hazmat/backends/openssl/ciphers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
class _CipherContext(object):
1818
_ENCRYPT = 1
1919
_DECRYPT = 0
20-
_MAX_CHUNK_SIZE = 2 ** 31
20+
_MAX_CHUNK_SIZE = 2 ** 31 - 1
2121

2222
def __init__(self, backend, cipher, mode, operation):
2323
self._backend = backend

tests/hazmat/primitives/test_ciphers.py

+9
Original file line numberDiff line numberDiff line change
@@ -333,3 +333,12 @@ def test_update_into_auto_chunking(self, backend, monkeypatch):
333333
decbuf = bytearray(527)
334334
decprocessed = decryptor.update_into(buf[:processed], decbuf)
335335
assert decbuf[:decprocessed] == pt
336+
337+
def test_max_chunk_size_fits_in_int32(self, backend):
338+
# max chunk must fit in signed int32 or else a call large enough to
339+
# cause chunking will result in the very OverflowError we want to
340+
# avoid with chunking.
341+
key = b"\x00" * 16
342+
c = ciphers.Cipher(AES(key), modes.ECB(), backend)
343+
encryptor = c.encryptor()
344+
backend._ffi.new("int *", encryptor._ctx._MAX_CHUNK_SIZE)

0 commit comments

Comments
 (0)