From 68e3de0357cd480ed1384377e31c927f6853cfeb Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 18 Feb 2019 17:12:50 +0000 Subject: [PATCH] Use name from header not alias when checking entry has expected name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, an entry’s potentially aliased name would be used when checking that it has a particular name. The alias would always be applied, irrespective of the name in the header. As a result, when there was a clashing hash and an entry with a particular index did not have the expected name, this would be concealed by the alias being applied and the name check being done with the alias. This commit reworks JarEntry to store the name in its header in addition to its alias, if any. When checking that the entry has the expected name, the unaliased name is passed in and the entry compares it with the name from the header rather than the alias. Closes gh-15981 --- .../java/org/springframework/boot/loader/jar/JarEntry.java | 7 +++++-- .../springframework/boot/loader/jar/JarFileEntries.java | 5 ++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarEntry.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarEntry.java index 9dca479ad9fc..d9f8a70c1981 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarEntry.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarEntry.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,6 +34,8 @@ class JarEntry extends java.util.jar.JarEntry implements FileHeader { private final AsciiBytes name; + private final AsciiBytes headerName; + private Certificate[] certificates; private CodeSigner[] codeSigners; @@ -45,6 +47,7 @@ class JarEntry extends java.util.jar.JarEntry implements FileHeader { JarEntry(JarFile jarFile, CentralDirectoryFileHeader header, AsciiBytes nameAlias) { super((nameAlias != null) ? nameAlias.toString() : header.getName().toString()); this.name = (nameAlias != null) ? nameAlias : header.getName(); + this.headerName = header.getName(); this.jarFile = jarFile; this.localHeaderOffset = header.getLocalHeaderOffset(); setCompressedSize(header.getCompressedSize()); @@ -62,7 +65,7 @@ AsciiBytes getAsciiBytesName() { @Override public boolean hasName(CharSequence name, char suffix) { - return this.name.matches(name, suffix); + return this.headerName.matches(name, suffix); } /** 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 d9abf28d3f92..5da3eb7c9fef 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 @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -305,8 +305,7 @@ private T getEntry(int hashCode, CharSequence name, int index = getFirstIndex(hashCode); while (index >= 0 && index < this.size && this.hashCodes[index] == hashCode) { T entry = getEntry(index, type, cacheEntry, nameAlias); - if (entry.hasName((nameAlias != null) ? nameAlias.toString() : name, - suffix)) { + if (entry.hasName(name, suffix)) { return entry; } index++;