#2910·brython

The zlib.compress() function crashes when the data size is greater than 102

Author: epeios-q37Created Aug 3, 2026Updated Aug 3, 2026

Hello Pierre,

Following code:

python
import zlib

print(zlib.compress(bytearray((0,) * 102))) # Works

print(zlib.compress(bytearray((0,) * 103))) # FAILS

displays under Brython (version 3.14.3 but also the development one):

b'x\x9cc\xa0\x0b\x00\x00\x00f\x00\x01'
Traceback (most recent call last):
  File <string>, line 5, in <module>
    print(zlib.compress(bytearray((0,) * 103))) # FAILS
  File VFS.zlib.py, line 405, in compress
    return bytes(compressor.compress(data)+compressor.flush())
  File VFS.zlib.py, line 490, in compress
    compress_dynamic(writer,store,lit_len_count,distance_count)
  File VFS.zlib.py, line 309, in compress_dynamic
    distance_codes=normalized(codelengths_from_frequencies(distance_count,15))
  File VFS.zlib.py, line 176, in codelengths_from_frequencies
    tree.reduce(maxlength)
  File VFS.zlib.py, line 136, in reduce
    while self.length()>maxlevels:
  File VFS.zlib.py, line 78, in length
    set_level(self.root)
  File VFS.zlib.py, line 73, in set_level
    for child in node.children:
AttributeError: 'Node' object has no attribute 'children'

and under Python:

b'x\x9cc`\xa0\x07\x00\x00\x00f\x00\x01'
b'x\x9cc`\xa0\x0b\x00\x00\x00g\x00\x01'

To reproduce: https://brython.info/tests/editor.html?lang=fr&code=import%20zlib%0A%0Aprint%28zlib.compress%28bytearray%28%280%2C%29%20*%20102%29%29%29%20%23%20Works%0A%0Aprint%28zlib.compress%28bytearray%28%280%2C%29%20*%20103%29%29%29%20%23%20FAILS

Thanks!