From 559cb1f69f9fdebf14634c2d328f8fd28bd813f8 Mon Sep 17 00:00:00 2001 From: gztong666 Date: Thu, 24 Sep 2026 18:05:59 +0800 Subject: [PATCH] Fix up-to-date check for invalid file URLs --- .../main/java/proguard/UpToDateChecker.java | 6 ++- .../kotlin/proguard/UpToDateCheckerTest.kt | 37 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 base/src/test/kotlin/proguard/UpToDateCheckerTest.kt diff --git a/base/src/main/java/proguard/UpToDateChecker.java b/base/src/main/java/proguard/UpToDateChecker.java index f89cf0da7..69b2a5122 100644 --- a/base/src/main/java/proguard/UpToDateChecker.java +++ b/base/src/main/java/proguard/UpToDateChecker.java @@ -136,7 +136,11 @@ public void updateInputModificationTime(URL url) { updateModificationTime(new File(url.toURI()), false); } - catch (URISyntaxException ignore) {} + catch (URISyntaxException exception) + { + // The input couldn't be checked, so conservatively consider the output outdated. + throw new IllegalStateException("Can't check the input modification time", exception); + } } } diff --git a/base/src/test/kotlin/proguard/UpToDateCheckerTest.kt b/base/src/test/kotlin/proguard/UpToDateCheckerTest.kt new file mode 100644 index 000000000..a5f06c547 --- /dev/null +++ b/base/src/test/kotlin/proguard/UpToDateCheckerTest.kt @@ -0,0 +1,37 @@ +package proguard + +import io.kotest.assertions.throwables.shouldNotThrowAny +import io.kotest.core.spec.style.FreeSpec +import java.io.File +import java.net.URL +import java.nio.file.Files + +class UpToDateCheckerTest : FreeSpec({ + "An invalid file URI does not hide an outdated obfuscation dictionary" { + val directory = Files.createTempDirectory("proguard-up-to-date-test").toFile() + + try { + val output = File(directory, "output.jar").apply { + createNewFile() + setLastModified(1_000L) + } + val dictionary = File(directory, "dictionary with spaces.txt").apply { + createNewFile() + setLastModified(2_000L) + } + + val configuration = Configuration().apply { + programJars = ClassPath().apply { + add(ClassPathEntry(output, true)) + } + obfuscationDictionary = URL(dictionary.toURI().toString().replace("%20", " ")) + } + + shouldNotThrowAny { + UpToDateChecker(configuration).check() + } + } finally { + directory.deleteRecursively() + } + } +})