Skip to content

fix(sdk): fail fast when a TDF manifest would exceed the read-side size cap (DSPX-4651) - #1019

Draft
dmihalcik-virtru wants to merge 1 commit into
DSPX-4496-count-ivfrom
DSPX-4651-manifest-fail-fast
Draft

dmihalcik-virtru wants to merge 1 commit into
DSPX-4496-count-ivfrom
DSPX-4651-manifest-fail-fast

Conversation

@dmihalcik-virtru

@dmihalcik-virtru dmihalcik-virtru commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

Stacked on #1018 (which is stacked on #1017). Review the parent PRs first; the diff shown here is only correct once GitHub is comparing against DSPX-4496-count-iv.

Jira: DSPX-4651 (sub-task of DSPX-4648, under epic DSPX-4502).

What

MANIFEST_MAX_SIZE (10 MB) was enforced only on the read path. This extracts the check into a shared assertManifestWithinSizeLimit() in lib/tdf3/src/utils/zip-reader.ts and calls it from writeStream() before the manifest is emitted.

Also fixes a >> 10 bitwise truncation in the read-side error message: for manifests ≥ 4 GiB the shift wraps and reports a nonsense size. Now Math.floor(n / 1024).

Why

Today it is possible to encrypt a large file successfully and produce a TDF that no reader can ever open. The write path had no opinion about manifest size; the read path rejects at 10 MB. A 5 GB file at the default 1 MiB segment size produces ~5,000 segments and is fine, but the failure mode scales in silently — and the whole point of the 50 TiB work (DSPX-4648) is that the manifest is the binding constraint, not the payload.

Failing at encrypt time turns a permanent data-loss-shaped bug into an actionable ConfigurationError that names the segment count and tells the caller to raise segmentSize.

Scope / what this does not do

This is the first of two pieces of DSPX-4651. The check still runs after the entire payload has been encrypted, so it wastes the whole encrypt before rejecting. Making it an up-front estimate from the source size, and raising the cap so 50 TiB can fit under it at all, is the rest of the sub-task and lands separately.

How to test

cd lib && npm run build && npx mocha 'dist/web/tests/mocha/unit/zip.spec.js'

New cases in lib/tests/mocha/unit/zip.spec.ts cover the boundary (at the limit passes, one byte over throws) and the ≥ 4 GiB message formatting.

Risk

Low, but it is a new rejection on the write path: a caller who was previously writing an unreadable TDF now gets an error instead. That is the intent. No existing test produces a manifest anywhere near 10 MB.

@dmihalcik-virtru
dmihalcik-virtru requested a review from a team as a code owner September 8, 2026 22:18
@coderabbitai

coderabbitai Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · 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

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

@dmihalcik-virtru
dmihalcik-virtru added this pull request to stack #1033 September 10, 2026 20:52
@dmihalcik-virtru
dmihalcik-virtru force-pushed the DSPX-4651-manifest-fail-fast branch from d3028cf to b671a6b Compare September 22, 2026 14:23
@dmihalcik-virtru
dmihalcik-virtru removed this pull request from stack #1033 September 22, 2026 14:24
@dmihalcik-virtru
dmihalcik-virtru force-pushed the DSPX-4651-manifest-fail-fast branch 2 times, most recently from b671a6b to 5ebc5fd Compare September 23, 2026 18:15
@github-actions

Copy link
Copy Markdown

X-Test Failure Report

coverage-lib
opentdf-sdk-lib
opentdf-ctl

@github-actions

Copy link
Copy Markdown

X-Test Failure Report

coverage-lib
opentdf-ctl
opentdf-sdk-lib

@github-actions

Copy link
Copy Markdown

X-Test Failure Report

coverage-lib
opentdf-sdk-lib
opentdf-ctl

@dmihalcik-virtru
dmihalcik-virtru force-pushed the DSPX-4651-manifest-fail-fast branch from 683c746 to 0cab1f8 Compare September 28, 2026 15:04
@dmihalcik-virtru
dmihalcik-virtru marked this pull request as draft September 28, 2026 15:08
@dmihalcik-virtru
dmihalcik-virtru force-pushed the DSPX-4496-count-iv branch 3 times, most recently from 783a75c to 901245b Compare October 6, 2026 18:33
…ze cap

Extracts the 10MB manifest size check shared by write and read into
assertManifestWithinSizeLimit (lib/tdf3/src/utils/zip-reader.ts) and calls it
from writeStream before the manifest is emitted, so an oversized manifest
(e.g. from a very large file at a small segment size) fails at encrypt time
with an actionable ConfigurationError instead of producing a TDF that is
permanently unreadable. Also fixes a >> 10 bitwise truncation bug in the
existing read-side error message for manifests >= 4GiB.

This is the first piece of DSPX-4651. The check still runs after the whole
payload has been encrypted; making it an up-front estimate, and raising the
cap so a 50 TiB file can fit under it at all, is the rest of that sub-task.

DSPX-4651
@github-actions

Copy link
Copy Markdown

@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
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