Skip to content

Commit f31ffbf

Browse files
committed
Don't duplicate META-INF entries in nested directory jars
Update `ZipContent` so that `META-INF` entries are no longer duplicated in nested jars created from directory entries. This aligns with the behavior of the classic loader and prevents the same META-INF file from being discovered twice. Fixes gh-38862
1 parent b218528 commit f31ffbf

File tree

3 files changed

+7
-14
lines changed

3 files changed

+7
-14
lines changed

spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/zip/ZipContent.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -637,10 +637,7 @@ private static ZipContent loadNestedDirectory(Source source, ZipContent zip, Ent
637637
.load(zip.data, pos);
638638
long namePos = pos + ZipCentralDirectoryFileHeaderRecord.FILE_NAME_OFFSET;
639639
short nameLen = centralRecord.fileNameLength();
640-
if (ZipString.startsWith(loader.buffer, zip.data, namePos, nameLen, META_INF) != -1) {
641-
loader.add(centralRecord, pos, false);
642-
}
643-
else if (ZipString.startsWith(loader.buffer, zip.data, namePos, nameLen, directoryName) != -1) {
640+
if (ZipString.startsWith(loader.buffer, zip.data, namePos, nameLen, directoryName) != -1) {
644641
loader.add(centralRecord, pos, true);
645642
}
646643
}

spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/NestedJarFileTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,8 @@ void createWhenNestedJarFileOpensJar() throws IOException {
105105
void createWhenNestedJarDirectoryOpensJar() throws IOException {
106106
try (NestedJarFile jar = new NestedJarFile(this.file, "d/")) {
107107
assertThat(jar.getName()).isEqualTo(this.file.getAbsolutePath() + "!/d/");
108-
assertThat(jar.size()).isEqualTo(3);
109-
assertThat(jar.stream().map(JarEntry::getName)).containsExactly("META-INF/", "META-INF/MANIFEST.MF",
110-
"9.dat");
108+
assertThat(jar.size()).isEqualTo(1);
109+
assertThat(jar.stream().map(JarEntry::getName)).containsExactly("9.dat");
111110
}
112111
}
113112

spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/zip/ZipContentTests.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,9 @@ void nestedJarFileWhenNameEndsInSlashThrowsException() {
210210
@Test
211211
void nestedDirectoryReturnsNestedJar() throws IOException {
212212
try (ZipContent nested = ZipContent.open(this.file.toPath(), "d/")) {
213-
assertThat(nested.size()).isEqualTo(3);
213+
assertThat(nested.size()).isEqualTo(1);
214214
assertThat(nested.getEntry("9.dat")).isNotNull();
215-
assertThat(nested.getEntry(0).getName()).isEqualTo("META-INF/");
216-
assertThat(nested.getEntry(1).getName()).isEqualTo("META-INF/MANIFEST.MF");
217-
assertThat(nested.getEntry(2).getName()).isEqualTo("9.dat");
215+
assertThat(nested.getEntry(0).getName()).isEqualTo("9.dat");
218216
}
219217
}
220218

@@ -230,9 +228,8 @@ void getDataWhenNestedDirectoryReturnsVirtualZipDataBlock() throws IOException {
230228
File file = new File(this.tempDir, "included.zip");
231229
write(file, nested.openRawZipData());
232230
try (ZipFile loadedZipFile = new ZipFile(file)) {
233-
assertThat(loadedZipFile.size()).isEqualTo(3);
234-
assertThat(loadedZipFile.stream().map(ZipEntry::getName)).containsExactly("META-INF/",
235-
"META-INF/MANIFEST.MF", "9.dat");
231+
assertThat(loadedZipFile.size()).isEqualTo(1);
232+
assertThat(loadedZipFile.stream().map(ZipEntry::getName)).containsExactly("9.dat");
236233
assertThat(loadedZipFile.getEntry("9.dat")).isNotNull();
237234
try (InputStream in = loadedZipFile.getInputStream(loadedZipFile.getEntry("9.dat"))) {
238235
ByteArrayOutputStream out = new ByteArrayOutputStream();

0 commit comments

Comments
 (0)