Conversation
janblom
commented
Feb 23, 2026
- replaced Ant (build tool) by Maven
- updated minor dependency versions, and major when possible
- checked for, and eliminated, known vulnerabilities
- added unit and integration tests (based on junit, assertj-swing and cacio-tta)
- updated README.md
src/test/java/org/ohdsi/usagi/indexBuilding/BerkeleyDbBuilderIT.java
Outdated
Show resolved
Hide resolved
aa13a49 to
d6d7689
Compare
| try (ZipInputStream zis = new ZipInputStream(is)) { | ||
| ZipEntry entry; | ||
| while ((entry = zis.getNextEntry()) != null) { | ||
| File newFile = new File(targetDir.toFile(), entry.getName()); |
Check failure
Code scanning / CodeQL
Arbitrary file access during archive extraction ("Zip Slip")
This autofix suggestion was applied.
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 1 month ago
To fix the issue, every ZipEntry destination path must be normalized and verified to remain within targetDir before any filesystem operation (directory creation or file writing) is performed. This prevents archive entries with .. or absolute paths from escaping the extraction root.
Concretely, in unzipResource we should:
- Convert
targetDirto an absolute, normalizedPathonce (e.g.,Path targetDirNormalized = targetDir.toAbsolutePath().normalize();). - For each
ZipEntry, resolve its name againsttargetDirNormalized(Path resolvedPath = targetDirNormalized.resolve(entry.getName()).normalize();). - Check that
resolvedPathstarts withtargetDirNormalizedusingPath.startsWith. If not, throw anIOException(or skip the entry). - Use this safe
resolvedPath(converted toFileif needed) formkdirs,getParentFile, andFileOutputStream.
We can keep the existing imports; we already import java.nio.file.Path and java.nio.file.Files, and we do not need any external libraries. The main code change is around line 21: replace the direct new File(targetDir.toFile(), entry.getName()) construction with the normalized Path approach and then derive a File from it. Also, we should ensure that directory creation uses Files.createDirectories (or keep mkdirs via File if we prefer), but the critical part is that all operations use the validated path.
| @@ -11,6 +11,7 @@ | ||
|
|
||
| public class TestUtils { | ||
| public static void unzipResource(String resourceName, Path targetDir) throws IOException { | ||
| Path targetDirNormalized = targetDir.toAbsolutePath().normalize(); | ||
| try (InputStream is = TestUtils.class.getResourceAsStream(resourceName)) { | ||
| if (is == null) { | ||
| throw new IOException("Resource not found: " + resourceName); | ||
| @@ -18,7 +19,11 @@ | ||
| try (ZipInputStream zis = new ZipInputStream(is)) { | ||
| ZipEntry entry; | ||
| while ((entry = zis.getNextEntry()) != null) { | ||
| File newFile = new File(targetDir.toFile(), entry.getName()); | ||
| Path resolvedPath = targetDirNormalized.resolve(entry.getName()).normalize(); | ||
| if (!resolvedPath.startsWith(targetDirNormalized)) { | ||
| throw new IOException("Entry is outside of the target dir: " + entry.getName()); | ||
| } | ||
| File newFile = resolvedPath.toFile(); | ||
| if (entry.isDirectory()) { | ||
| newFile.mkdirs(); | ||
| } else { |
… of anti-aliasing setting
…test results cannot be swapped
4975ccc to
83802f1
Compare