Skip to content

Pass the ownership of output buffers to consumers during compression - #446

Merged
weichsel merged 2 commits into
mainfrom
fix/consumer-data-ownership
Nov 20, 2026
Merged

weichsel merged 2 commits into
mainfrom
fix/consumer-data-ownership

Conversation

@weichsel

Copy link
Copy Markdown
Owner

On Apple platforms, Data.compress, Data.decompress and Archive.extract passed consumers Data that referenced a reused internal buffer. Data that a consumer kept changed with the next chunk and referenced deallocated memory after the call returned.

Each non-empty chunk now owns the buffer it was written to. There is no copy, and throughput is unchanged in benchmarks.

Also moves the test lists out of ZIPFoundationTests.swift, which had reached the maximum file length.

ZIPFoundationTests.swift reached the maximum file length, so new tests
could no longer be registered.
Consumers received data that referenced a buffer that was reused for the
next chunk and deallocated when compression or decompression returned.
Data that a consumer kept changed and referenced deallocated memory.
Each non-empty chunk now owns the buffer it was written to.
@weichsel
weichsel merged commit 8125b1b into main Nov 20, 2026
13 checks passed
@weichsel
weichsel deleted the fix/consumer-data-ownership branch November 20, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant