Skip to content

Commit

Permalink
Check on path/size of unzipped artifact re: CWE-409 (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdon authored Mar 18, 2024
1 parent 9df3dfc commit 22c4da8
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -124,10 +123,14 @@ public static NaturalEarthDb fromSqlite(Path path, Path unzippedDir) {
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("No .sqlite file found inside " + path));
extracted = unzippedDir.resolve(URLEncoder.encode(zipEntry.toString(), StandardCharsets.UTF_8));
if (!extracted.startsWith(unzippedDir)) {
throw new IllegalArgumentException(
"Zip file tried to extract child outside of folder: " + zipEntry.getFileName());
}
FileUtils.createParentDirectories(extracted);
if (FileUtils.isNewer(path, extracted)) {
LOGGER.info("unzipping {} to {}", path.toAbsolutePath(), extracted);
Files.copy(Files.newInputStream(zipEntry), extracted, StandardCopyOption.REPLACE_EXISTING);
FileUtils.safeCopy(Files.newInputStream(zipEntry), extracted);
}
}
uri = "jdbc:sqlite:" + extracted.toAbsolutePath();
Expand Down

0 comments on commit 22c4da8

Please sign in to comment.