From e0030094e281967320ad2010caa3eb5511866db8 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Tue, 15 Sep 2020 08:42:58 -0700 Subject: [PATCH] Fix missing jar entry certificates Ensure that the source jar entry is closed before reading certificates and code signers from the entry. gh-19041 --- .../boot/loader/jar/JarFileEntries.java | 3 ++- .../springframework/boot/loader/jar/JarFileTests.java | 11 +++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFileEntries.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFileEntries.java index af8b3967af..df3321d965 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFileEntries.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFileEntries.java @@ -353,11 +353,12 @@ class JarFileEntries implements CentralDirectoryVisitor, Iterable { try (JarInputStream certifiedJarStream = new JarInputStream(this.jarFile.getData().getInputStream())) { java.util.jar.JarEntry certifiedEntry = null; while ((certifiedEntry = certifiedJarStream.getNextJarEntry()) != null) { + // Entry must be closed to trigger a read and set entry certificates + certifiedJarStream.closeEntry(); int index = getEntryIndex(certifiedEntry.getName()); if (index != -1) { certifications[index] = JarEntryCertification.from(certifiedEntry); } - certifiedJarStream.closeEntry(); } } this.certifications = certifications; diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/JarFileTests.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/JarFileTests.java index 50daa7a0c4..9ac4a4b217 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/JarFileTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/JarFileTests.java @@ -385,10 +385,13 @@ public class JarFileTests { while (actualEntries.hasMoreElements()) { JarEntry actualEntry = actualEntries.nextElement(); java.util.jar.JarEntry expectedEntry = expected.getJarEntry(actualEntry.getName()); - assertThat(actualEntry.getCertificates()).as(actualEntry.getName()) - .isEqualTo(expectedEntry.getCertificates()); - assertThat(actualEntry.getCodeSigners()).as(actualEntry.getName()) - .isEqualTo(expectedEntry.getCodeSigners()); + StreamUtils.drain(expected.getInputStream(expectedEntry)); + if (!actualEntry.getName().equals("META-INF/MANIFEST.MF")) { + assertThat(actualEntry.getCertificates()).as(actualEntry.getName()) + .isEqualTo(expectedEntry.getCertificates()); + assertThat(actualEntry.getCodeSigners()).as(actualEntry.getName()) + .isEqualTo(expectedEntry.getCodeSigners()); + } } assertThat(stopWatch.getTotalTimeSeconds()).isLessThan(3.0); }