Skip to content

fix: ZstdSkippableContent defensively copies its bytes#21

Merged
dfa1 merged 1 commit into
mainfrom
fix/skippable-defensive-copy
Jun 26, 2026
Merged

fix: ZstdSkippableContent defensively copies its bytes#21
dfa1 merged 1 commit into
mainfrom
fix/skippable-defensive-copy

Conversation

@dfa1

@dfa1 dfa1 commented Jun 26, 2026

Copy link
Copy Markdown
Owner

ZstdSkippableContent is a value type, but it stored the caller's byte[] and returned it from content() uncopied — so the "immutable" record could be mutated through the array passed to the constructor or the one handed back by the accessor.

Clone in the compact constructor and in the content() accessor, matching ZstdDictionary's copy-in (of) / copy-out (toByteArray) discipline. equals/hashCode/toString keep using the internal field directly (no extra copies).

Found during a code-quality inspection of the module.

Test

New defensivelyCopiesContentInAndOut asserts mutating both the source array and an accessor result leaves the record's bytes unchanged. ./mvnw -pl zstd -am test green, checkstyle + javadoc clean.

🤖 Generated with Claude Code

The record stored the caller's array and handed it back from content()
uncopied, so a "value" object could be mutated through the input array
or the accessor result. Clone in the compact constructor and in the
content() accessor, matching ZstdDictionary's copy-in/copy-out. Add a
test that mutating the source array and the accessor result leaves the
record untouched.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@dfa1 dfa1 merged commit a5f4aa0 into main Jun 26, 2026
1 check passed
@dfa1 dfa1 deleted the fix/skippable-defensive-copy branch June 26, 2026 20:39
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