Support getComment() on a nested JarFile
Previously, calling getComment() on a nested jar file would result in the outer jar file's comment being returned. This commit updates the loader's JarFile to read the file's comment from the central directory end record and return it from getComment(). Fixes gh-18128
This commit is contained in:
@@ -123,4 +123,10 @@ class CentralDirectoryEndRecord {
|
||||
return (int) numberOfRecords;
|
||||
}
|
||||
|
||||
String getComment() {
|
||||
int commentLength = (int) Bytes.littleEndianValue(this.block, this.offset + COMMENT_LENGTH_OFFSET, 2);
|
||||
AsciiBytes comment = new AsciiBytes(this.block, this.offset + COMMENT_LENGTH_OFFSET + 2, commentLength);
|
||||
return comment.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -80,6 +80,8 @@ public class JarFile extends java.util.jar.JarFile {
|
||||
|
||||
private boolean signed;
|
||||
|
||||
private String comment;
|
||||
|
||||
/**
|
||||
* Create a new {@link JarFile} backed by the specified file.
|
||||
* @param file the root jar file
|
||||
@@ -146,6 +148,7 @@ public class JarFile extends java.util.jar.JarFile {
|
||||
|
||||
@Override
|
||||
public void visitStart(CentralDirectoryEndRecord endRecord, RandomAccessData centralDirectoryData) {
|
||||
JarFile.this.comment = endRecord.getComment();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -290,6 +293,11 @@ public class JarFile extends java.util.jar.JarFile {
|
||||
JarFileType.NESTED_JAR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComment() {
|
||||
return this.comment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return this.entries.getSize();
|
||||
|
||||
Reference in New Issue
Block a user