Skip to content

Stop BytesCodec from mutating its input buffer#433

Merged
manzt merged 1 commit into
mainfrom
push-vxvkupnwqquv
Jun 24, 2026
Merged

Stop BytesCodec from mutating its input buffer#433
manzt merged 1 commit into
mainfrom
push-vxvkupnwqquv

Conversation

@manzt

@manzt manzt commented Jun 24, 2026

Copy link
Copy Markdown
Owner

Fixes #431

BytesCodec byte-swaps big-endian data in place. When an uncompressed chunk is served from withByteCaching, the store hands back the same Uint8Array on every cache hit, so each decode re-swaps the cached buffer. The result is that repeated reads of the same chunk alternate between correct and corrupt values.

These changes copy before swapping on both encode and decode so the codec never mutates a buffer it doesn't own. The extra copy only happens on the big-endian-on-little-endian path; the common path is untouched.

Fixes #431

BytesCodec byte-swaps big-endian data in place. When an uncompressed
chunk is served from `withByteCaching`, the store hands back the same
Uint8Array on every cache hit, so each decode re-swaps the cached
buffer. The result is that repeated reads of the same chunk alternate
between correct and corrupt values.

These changes copy before swapping on both encode and decode so the
codec never mutates a buffer it doesn't own. The extra copy only happens
on the big-endian-on-little-endian path; the common path is untouched.
@manzt manzt added the bug Something isn't working label Jun 24, 2026
@changeset-bot

changeset-bot Bot commented Jun 24, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 13ad340

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
zarrita Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@manzt manzt changed the title Stop BytesCodec from mutating its input buffer Stop BytesCodec from mutating its input buffer Jun 24, 2026
@manzt
manzt merged commit 9cc1db2 into main Jun 24, 2026
2 checks passed
@manzt
manzt deleted the push-vxvkupnwqquv branch June 24, 2026 14:40
@github-actions github-actions Bot mentioned this pull request Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Caching of big-endian datasets on little-endian machines creates chaos

1 participant