Skip to content

fix(sdk): reject non-positive segment sizes in writeStream (DSPX-4496) - #1059

Merged
dmihalcik-virtru merged 1 commit into
mainfrom
DSPX-4496-positive-segment-size
Oct 7, 2026
Merged

dmihalcik-virtru merged 1 commit into
mainfrom
DSPX-4496-positive-segment-size

Conversation

@dmihalcik-virtru

@dmihalcik-virtru dmihalcik-virtru commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

What

  • writeStream now rejects a segment size that isn't a positive integer, throwing a ConfigurationError.
  • InvalidFileError gets its own name, like its sibling error classes. It used to report itself as TdfError.

Why

client.encrypt passes windowSize straight to the writer, and its destructuring default only applies when the value is undefined.

  • windowSize: 0 made the segmentation loop spin forever, because it never collects enough bytes to emit a zero-length segment.
  • A fractional or negative size wrote a manifest whose segment sizes no reader can follow.

How to test

cd lib && npm test. The new test "rejects a zero window size instead of hanging" fails on main by timing out.

Risk

Low. Valid segment sizes behave exactly as before.

DSPX-4496 series

Part PR Base Depends on
1 of 6 #1059 reject non-positive segment sizes main —
2 of 6 #1060 require 12-byte AES-GCM IVs main —
3 of 6 #1061 calculate encrypted segment size main —
4 of 6 #1062 default segment size 2 MiB main —
5 of 6 #1063 AesGcmEncryptor SPI DSPX-4496-encrypted-segment-size #1061
6 of 6 #1018 writer IVs from the CryptoService encryptor DSPX-4496-aes-gcm-encryptor #1063

#1059, #1060 and #1062 stand alone. #1061 ← #1063 ← #1018 is a stack.

Summary by CodeRabbit

  • Bug Fixes
    • Stream encryption now rejects segment sizes that are zero, negative, or fractional, reporting a configuration error that includes the supplied value.
    • Invalid file errors now consistently identify themselves by name, making them easier to distinguish from other errors.

`client.encrypt` forwards `windowSize` to the writer unchecked, and its
destructuring default only fires on `undefined`. A zero window spun forever
in the segmentation loop; a fractional or negative one wrote a manifest whose
segment sizes no reader can follow. Fail fast with a ConfigurationError.

Also give InvalidFileError its own `name`, like its sibling error classes, so
it no longer reports itself as a TdfError.

Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 52fe6fab-6a2b-4f6b-a0f0-4ed1c370b6cb
📥 Commits

Reviewing files that changed from the base of the PR and between 55a0521 and e818246.

📒 Files selected for processing (3)
  • lib/src/errors.ts
  • lib/tdf3/src/tdf.ts
  • lib/tests/mocha/encrypt-decrypt.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The changes set the InvalidFileError name explicitly and add positive-integer validation for segment sizes in writeStream. A regression test checks that encryption rejects windowSize: 0 with a ConfigurationError.

Changes

Invalid file error name

Layer / File(s) Summary
Set invalid file error name
lib/src/errors.ts
InvalidFileError now sets its name property to InvalidFileError.

Segment size validation

Layer / File(s) Summary
Validate segment size during encryption
lib/tdf3/src/tdf.ts, lib/tests/mocha/encrypt-decrypt.spec.ts
writeStream rejects segment sizes that are not positive integers. The regression test checks that windowSize: 0 produces a ConfigurationError.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: elizabethhealy

Merge Risk: ⚪ Minimal · up to e8182

The change rejects invalid segment sizes, and no issue requiring a fix before merge was identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: writeStream rejects invalid segment sizes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks the segment size,
And sees the zero-size error rise.
The file error names itself,
No mystery left upon the shelf.
The tests hop in to check the way,
Then nibble carrots through the day.

Comment @coderabbitai help to get the list of available commands.

@sonarqubecloud

sonarqubecloud Bot commented Oct 6, 2026

Copy link
Copy Markdown

@dmihalcik-virtru
dmihalcik-virtru marked this pull request as ready for review October 6, 2026 19:15
@dmihalcik-virtru
dmihalcik-virtru requested a review from a team as a code owner October 6, 2026 19:15
@dmihalcik-virtru
dmihalcik-virtru added this pull request to the merge queue Oct 7, 2026
Merged via the queue into main with commit 158ff29 Oct 7, 2026
31 checks passed
@dmihalcik-virtru
dmihalcik-virtru deleted the DSPX-4496-positive-segment-size branch October 7, 2026 13:07
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.

2 participants