Skip to content

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

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

fix(sdk): fail fast when a TDF manifest would exceed the read-side size cap (DSPX-4651)#1019
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.

…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
@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

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review (1)
  • main

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 57d63f5b-96c4-4a86-9c5f-227f9ffb7904

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

@sonarqubecloud

sonarqubecloud Bot commented Sep 8, 2026

Copy link
Copy Markdown

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