Skip to content

fix: stream truncation detection, heap-segment guards, ZDICT layouts#1

Merged
dfa1 merged 4 commits into
mainfrom
fix/stream-truncation-and-alloc
Jun 26, 2026
Merged

fix: stream truncation detection, heap-segment guards, ZDICT layouts#1
dfa1 merged 4 commits into
mainfrom
fix/stream-truncation-and-alloc

Conversation

@dfa1

@dfa1 dfa1 commented Jun 26, 2026

Copy link
Copy Markdown
Owner

Review-driven correctness + robustness fixes for the FFM bindings.

Correctness

  • Truncated streams now throw. ZstdInputStream silently returned a clean EOF when the underlying stream ended mid-frame, dropping data without error. It now tracks zstd's outstanding-input hint from decompressStream and throws ZstdException on a non-zero hint at EOF. Empty input stays a clean EOF.

Robustness / UX

  • Zero-copy heap-segment guard. Passing an on-heap MemorySegment to a zero-copy API previously crashed with a cryptic FFM linker error. Added Zstd.requireNative (isNative() check) at each entry — compress/decompress on both contexts, the compress stream, and decompressedSize — failing fast with a clear message.

Maintainability

  • ZDICT cover params as MemoryLayout. Replaced the hand-coded ZDICT_cover/fastCover struct offsets (the most fragile spot in the codebase) with named MemoryLayout structs; offsets and allocation size now derive from the layout.

Performance

  • Reuse a single-byte scratch buffer in read()/write(int) instead of allocating new byte[1] per call (streams are already non-thread-safe).

Tests

  • 130 pass (+7): truncation cases (drop 1/8/64 bytes, plus empty-input clean-EOF) and heap-segment rejection on compress/decompress/decompressedSize.
  • Checkstyle + Javadoc gates clean.

🤖 Generated with Claude Code

dfa1 and others added 4 commits June 26, 2026 09:27
Mirror the vortex-java publish flow:
- root pom: scm, plugin-version properties, and a `release` profile (source +
  javadoc jars, gpg sign, central-publishing-maven-plugin with autoPublish)
- per-module <description> on every deployable artifact (Central requires
  name/description/url/license/scm/developer); benchmark + integration-tests
  already set maven.deploy.skip
- .github/workflows/publish.yml: on a v* tag, build (checkout submodule + Zig),
  deploy -Prelease, then cut a GitHub release from CHANGELOG.md
- CHANGELOG.md with the 0.1 notes

Release: set repo secrets CENTRAL_USERNAME/PASSWORD, GPG_PRIVATE_KEY,
GPG_PASSPHRASE; register io.github.dfa1 on central.sonatype.com; push tag v0.1.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
ZstdInputStream silently returned clean EOF when the underlying stream
ended mid-frame, losing data without error. Track zstd's outstanding-input
hint from decompressStream and throw ZstdException on a non-zero hint at
EOF. Empty input stays a clean EOF.

Also reuse a single-byte scratch buffer in read()/write(int) instead of
allocating new byte[1] per call (streams are already non-thread-safe).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…layouts

Zero-copy MemorySegment APIs dereference the segment address in C, so a
heap-backed segment crashed with a cryptic FFM linker error. Add an
isNative() guard (Zstd.requireNative) at each zero-copy entry — compress
/decompress on the contexts and stream, plus decompressedSize — failing
fast with a clear message.

Replace the hand-coded ZDICT_cover/fastCover param struct offsets in
optimize() with named MemoryLayout structs; offsets and allocation size
now derive from the layout instead of magic numbers.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Mirror vortex-java: release:prepare drops -SNAPSHOT, tags v<version>
(pushChanges=false, autoVersionSubmodules), bumps to next snapshot. Pushing the
v* tag triggers publish.yml -> deploy -Prelease to Maven Central. Document the
flow in the release profile comment.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@dfa1 dfa1 merged commit 004bdbd into main Jun 26, 2026
1 check passed
@dfa1 dfa1 deleted the fix/stream-truncation-and-alloc branch June 26, 2026 10:52
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