Skip to content

Commit e12a0a4

Browse files
Try fix security issue
1 parent b6eb9f5 commit e12a0a4

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

gxcompress/src/main/java/com/genexus/compression/GXCompressor.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -408,11 +408,12 @@ public static void decompressJar(File jarFile, String outputPath) throws IOExcep
408408
JarEntry entry;
409409
byte[] buffer = new byte[1024];
410410
while ((entry = jis.getNextJarEntry()) != null) {
411-
File outputFile = new File(outputDir, entry.getName());
412-
if (entry.isDirectory()) {
413-
if (!outputFile.exists() && !outputFile.mkdirs()) {
414-
throw new IOException("Failed to create directory " + outputFile.getAbsolutePath());
415-
}
411+
File outputFile = new File(outputDir, entry.getName()).getCanonicalFile();
412+
if (!outputFile.getPath().startsWith(outputDir.getCanonicalPath() + File.separator)) {
413+
throw new IOException("Entry is outside of the target dir: " + entry.getName());
414+
}
415+
if (entry.isDirectory() && !outputFile.exists() && !outputFile.mkdirs()) {
416+
throw new IOException("Failed to create directory " + outputFile.getAbsolutePath());
416417
} else {
417418
try (FileOutputStream fos = new FileOutputStream(outputFile)) {
418419
int len;

0 commit comments

Comments
 (0)