Skip to content

Commit 22c4da8

Browse files
authored
Check on path/size of unzipped artifact re: CWE-409 (#222)
1 parent 9df3dfc commit 22c4da8

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

tiles/src/main/java/com/protomaps/basemap/feature/NaturalEarthDb.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import java.nio.file.FileSystems;
99
import java.nio.file.Files;
1010
import java.nio.file.Path;
11-
import java.nio.file.StandardCopyOption;
1211
import java.sql.*;
1312
import java.util.ArrayList;
1413
import java.util.List;
@@ -124,10 +123,14 @@ public static NaturalEarthDb fromSqlite(Path path, Path unzippedDir) {
124123
.findFirst()
125124
.orElseThrow(() -> new IllegalArgumentException("No .sqlite file found inside " + path));
126125
extracted = unzippedDir.resolve(URLEncoder.encode(zipEntry.toString(), StandardCharsets.UTF_8));
126+
if (!extracted.startsWith(unzippedDir)) {
127+
throw new IllegalArgumentException(
128+
"Zip file tried to extract child outside of folder: " + zipEntry.getFileName());
129+
}
127130
FileUtils.createParentDirectories(extracted);
128131
if (FileUtils.isNewer(path, extracted)) {
129132
LOGGER.info("unzipping {} to {}", path.toAbsolutePath(), extracted);
130-
Files.copy(Files.newInputStream(zipEntry), extracted, StandardCopyOption.REPLACE_EXISTING);
133+
FileUtils.safeCopy(Files.newInputStream(zipEntry), extracted);
131134
}
132135
}
133136
uri = "jdbc:sqlite:" + extracted.toAbsolutePath();

0 commit comments

Comments
 (0)