Skip to content

Commit 90a88da

Browse files
pflynn-virtruclaude
andcommitted
fix(sdk): stop isTDF rejecting archives by entry count
isTDF required the archive to hold exactly two entries. An archive carrying both manifest names holds three, and TDFReader now reads it by preferring the spec name -- so the sniffer rejected what the reader it screens for accepts. The count also made isTDF stricter than the reader generally: the spec fixes where the manifest lives, not what else the archive may hold. Entry presence is what isTDF was checking for; the count was never part of the structure it describes. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Signed-off-by: Paul Flynn <pflynn-virtru@users.noreply.github.com>
1 parent 842b7da commit 90a88da

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

‎sdk/src/main/java/io/opentdf/platform/sdk/SDK.java‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ public Optional<SrtSigner> getSrtSigner() {
159159
* a `manifest.json` and a `0.payload`
160160
* <p>
161161
* The off-spec `0.manifest.json` that this SDK writes is also accepted, matching
162-
* {@link TDFReader}.
162+
* {@link TDFReader}. Entries beyond the manifest and payload are ignored rather than
163+
* disqualifying: an archive carrying both manifest names holds three, and the reader
164+
* accepts it, so a count check here would reject what the reader it screens for reads.
163165
*
164166
* @param channel A channel containing the bytes of the potential Z-TDF
165167
* @return `true` if
@@ -172,9 +174,6 @@ public static boolean isTDF(SeekableByteChannel channel) {
172174
return false;
173175
}
174176
var entries = zipReader.getEntries();
175-
if (entries.size() != 2) {
176-
return false;
177-
}
178177
return entries.stream().anyMatch(e -> TDFWriter.TDF_MANIFEST_FILE_NAME_SPEC.equals(e.getName())
179178
|| TDFWriter.TDF_MANIFEST_FILE_NAME.equals(e.getName()))
180179
&& entries.stream().anyMatch(e -> TDFWriter.TDF_PAYLOAD_FILE_NAME.equals(e.getName()));

‎sdk/src/test/java/io/opentdf/platform/sdk/SDKTest.java‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,24 @@ void testExaminingTDFWithSpecManifestName() throws IOException {
4343
}
4444
}
4545

46+
/**
47+
* The reader accepts an archive carrying both manifest names, so the sniffer that
48+
* screens for it must not turn that third entry into a rejection.
49+
*/
50+
@Test
51+
void testExaminingTDFWithBothManifestNames() throws IOException {
52+
try (var chan = zipOf("0.payload", "manifest.json", "0.manifest.json")) {
53+
assertThat(SDK.isTDF(chan)).isTrue();
54+
}
55+
}
56+
57+
@Test
58+
void testExaminingTDFWithAnExtraEntry() throws IOException {
59+
try (var chan = zipOf("0.payload", "manifest.json", "something-else")) {
60+
assertThat(SDK.isTDF(chan)).isTrue();
61+
}
62+
}
63+
4664
@Test
4765
void testExaminingZipWithNoManifest() throws IOException {
4866
try (var chan = zipOf("0.payload", "something-else")) {

0 commit comments

Comments
 (0)