Skip to content

Commit 31fec23

Browse files
sgramponeBeta Bot
authored andcommitted
Cherry pick branch 'genexuslabs:fix/gxcompress-abitrary-file-access' into beta
1 parent 6cef10b commit 31fec23

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,12 +634,20 @@ private static void decompress7z(File archive, String directory) throws IOExcept
634634
}
635635
}
636636

637+
638+
637639
private static void decompressTar(File archive, String directory) throws IOException {
638640
byte[] buffer = new byte[BUFFER_SIZE];
639641
try (TarArchiveInputStream tis = new TarArchiveInputStream(Files.newInputStream(archive.toPath()))) {
640642
TarArchiveEntry entry;
641643
while ((entry = tis.getNextEntry()) != null) {
644+
642645
File newFile = new File(directory, entry.getName());
646+
if(!newFile.getAbsolutePath().equals(newFile.getCanonicalPath()))
647+
{
648+
log.error(DIRECTORY_ATTACK + "{}", newFile.getAbsolutePath());
649+
return;
650+
}
643651
if (entry.isDirectory()) {
644652
if (!newFile.isDirectory() && !newFile.mkdirs()) {
645653
throw new IOException("Failed to create directory " + newFile);

0 commit comments

Comments
 (0)