Skip to content

Stream helpers truncate compressed iterators at empty chunks #2252

Backlog

Description

@khushalx

read_in_chunks and exhaust_iterator stop at the first empty chunk from an iterator, even when more data follows. Empty output is normal for a streaming compressor while it buffers input. Passing that iterator to these helpers truncates the compressed file.

Reproduced on trunk (b2e794d), Python 3.12:

import zlib
from libcloud.utils.files import exhaust_iterator, read_in_chunks

compressor = zlib.compressobj()
chunks = [compressor.compress(row) for row in (b"first row\n", b"second row\n")]
chunks.append(compressor.flush())
print([len(chunk) for chunk in chunks])  # includes an empty chunk

zlib.decompress(exhaust_iterator(iter(chunks)))
# zlib.error: incomplete or truncated stream

zlib.decompress(b"".join(read_in_chunks(iter(chunks))))
# same error

Both helpers should consume an iterator until StopIteration. This affects the Backblaze B2 upload paths that use exhaust_iterator, as well as callers using read_in_chunks to prepare a compressed upload.

AI disclosure: Codex reproduced the failure and prepared the fix and tests.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions