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
This commit is contained in:
parent
b2185282d4
commit
f31ffbf927
|
@ -637,10 +637,7 @@ public final class ZipContent implements Closeable {
|
|||
.load(zip.data, pos);
|
||||
long namePos = pos + ZipCentralDirectoryFileHeaderRecord.FILE_NAME_OFFSET;
|
||||
short nameLen = centralRecord.fileNameLength();
|
||||
if (ZipString.startsWith(loader.buffer, zip.data, namePos, nameLen, META_INF) != -1) {
|
||||
loader.add(centralRecord, pos, false);
|
||||
}
|
||||
else if (ZipString.startsWith(loader.buffer, zip.data, namePos, nameLen, directoryName) != -1) {
|
||||
if (ZipString.startsWith(loader.buffer, zip.data, namePos, nameLen, directoryName) != -1) {
|
||||
loader.add(centralRecord, pos, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,9 +105,8 @@ class NestedJarFileTests {
|
|||
void createWhenNestedJarDirectoryOpensJar() throws IOException {
|
||||
try (NestedJarFile jar = new NestedJarFile(this.file, "d/")) {
|
||||
assertThat(jar.getName()).isEqualTo(this.file.getAbsolutePath() + "!/d/");
|
||||
assertThat(jar.size()).isEqualTo(3);
|
||||
assertThat(jar.stream().map(JarEntry::getName)).containsExactly("META-INF/", "META-INF/MANIFEST.MF",
|
||||
"9.dat");
|
||||
assertThat(jar.size()).isEqualTo(1);
|
||||
assertThat(jar.stream().map(JarEntry::getName)).containsExactly("9.dat");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -210,11 +210,9 @@ class ZipContentTests {
|
|||
@Test
|
||||
void nestedDirectoryReturnsNestedJar() throws IOException {
|
||||
try (ZipContent nested = ZipContent.open(this.file.toPath(), "d/")) {
|
||||
assertThat(nested.size()).isEqualTo(3);
|
||||
assertThat(nested.size()).isEqualTo(1);
|
||||
assertThat(nested.getEntry("9.dat")).isNotNull();
|
||||
assertThat(nested.getEntry(0).getName()).isEqualTo("META-INF/");
|
||||
assertThat(nested.getEntry(1).getName()).isEqualTo("META-INF/MANIFEST.MF");
|
||||
assertThat(nested.getEntry(2).getName()).isEqualTo("9.dat");
|
||||
assertThat(nested.getEntry(0).getName()).isEqualTo("9.dat");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -230,9 +228,8 @@ class ZipContentTests {
|
|||
File file = new File(this.tempDir, "included.zip");
|
||||
write(file, nested.openRawZipData());
|
||||
try (ZipFile loadedZipFile = new ZipFile(file)) {
|
||||
assertThat(loadedZipFile.size()).isEqualTo(3);
|
||||
assertThat(loadedZipFile.stream().map(ZipEntry::getName)).containsExactly("META-INF/",
|
||||
"META-INF/MANIFEST.MF", "9.dat");
|
||||
assertThat(loadedZipFile.size()).isEqualTo(1);
|
||||
assertThat(loadedZipFile.stream().map(ZipEntry::getName)).containsExactly("9.dat");
|
||||
assertThat(loadedZipFile.getEntry("9.dat")).isNotNull();
|
||||
try (InputStream in = loadedZipFile.getInputStream(loadedZipFile.getEntry("9.dat"))) {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
|
|
Loading…
Reference in New Issue