Skip to content

Commit 68e3de0

Browse files
committed
Use name from header not alias when checking entry has expected name
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
1 parent 20c39dc commit 68e3de0

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarEntry.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* 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 {
3434

3535
private final AsciiBytes name;
3636

37+
private final AsciiBytes headerName;
38+
3739
private Certificate[] certificates;
3840

3941
private CodeSigner[] codeSigners;
@@ -45,6 +47,7 @@ class JarEntry extends java.util.jar.JarEntry implements FileHeader {
4547
JarEntry(JarFile jarFile, CentralDirectoryFileHeader header, AsciiBytes nameAlias) {
4648
super((nameAlias != null) ? nameAlias.toString() : header.getName().toString());
4749
this.name = (nameAlias != null) ? nameAlias : header.getName();
50+
this.headerName = header.getName();
4851
this.jarFile = jarFile;
4952
this.localHeaderOffset = header.getLocalHeaderOffset();
5053
setCompressedSize(header.getCompressedSize());
@@ -62,7 +65,7 @@ AsciiBytes getAsciiBytesName() {
6265

6366
@Override
6467
public boolean hasName(CharSequence name, char suffix) {
65-
return this.name.matches(name, suffix);
68+
return this.headerName.matches(name, suffix);
6669
}
6770

6871
/**

spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFileEntries.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -305,8 +305,7 @@ private <T extends FileHeader> T getEntry(int hashCode, CharSequence name,
305305
int index = getFirstIndex(hashCode);
306306
while (index >= 0 && index < this.size && this.hashCodes[index] == hashCode) {
307307
T entry = getEntry(index, type, cacheEntry, nameAlias);
308-
if (entry.hasName((nameAlias != null) ? nameAlias.toString() : name,
309-
suffix)) {
308+
if (entry.hasName(name, suffix)) {
310309
return entry;
311310
}
312311
index++;

0 commit comments

Comments
 (0)