Skip to content

Commit

Permalink
Fix issue #368 remove JAR signature related files to prevent JAR sign…
Browse files Browse the repository at this point in the history
…ature verification
  • Loading branch information
johnsonlee committed Aug 22, 2022
1 parent 769b75f commit ca782f8
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ fun ZipFile.transform(
runnable.run()
}))

entries().asSequence().forEach { entry ->
entries().asSequence().filterNot {
isJarSignatureRelatedFiles(it.name)
}.forEach { entry ->
if (!entries.contains(entry.name)) {
val zae = entryFactory(entry)
val stream = InputStreamSupplier {
Expand Down Expand Up @@ -108,7 +110,9 @@ fun ZipInputStream.transform(
val entries = mutableSetOf<String>()

while (true) {
val entry = nextEntry?.takeIf { true } ?: break
val entry = nextEntry?.takeUnless {
isJarSignatureRelatedFiles(it.name)
} ?: break
if (!entries.contains(entry.name)) {
val zae = entryFactory(entry)
val data = readBytes()
Expand All @@ -131,6 +135,12 @@ fun ZipInputStream.transform(
transform(it, entryFactory, transformer)
}

private val JAR_SIGNATURE_EXTENSIONS = setOf("SF", "RSA", "DSA", "EC")

private fun isJarSignatureRelatedFiles(name: String): Boolean {
return name.startsWith("META-INF/") && name.substringAfterLast('.') in JAR_SIGNATURE_EXTENSIONS
}

private const val DEFAULT_BUFFER_SIZE = 8 * 1024

private fun InputStream.readBytes(estimatedSize: Int = DEFAULT_BUFFER_SIZE): ByteArray {
Expand Down

0 comments on commit ca782f8

Please sign in to comment.