File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed
src/test/java/org/ohdsi/usagi Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change 1111
1212public class TestUtils {
1313 public static void unzipResource (String resourceName , Path targetDir ) throws IOException {
14+ Path targetDirNormalized = targetDir .toAbsolutePath ().normalize ();
1415 try (InputStream is = TestUtils .class .getResourceAsStream (resourceName )) {
1516 if (is == null ) {
1617 throw new IOException ("Resource not found: " + resourceName );
1718 }
1819 try (ZipInputStream zis = new ZipInputStream (is )) {
1920 ZipEntry entry ;
2021 while ((entry = zis .getNextEntry ()) != null ) {
21- File newFile = new File (targetDir .toFile (), entry .getName ());
22+ Path resolvedPath = targetDirNormalized .resolve (entry .getName ()).normalize ();
23+ if (!resolvedPath .startsWith (targetDirNormalized )) {
24+ throw new IOException ("Entry is outside of the target dir: " + entry .getName ());
25+ }
26+ File newFile = resolvedPath .toFile ();
2227 if (entry .isDirectory ()) {
2328 newFile .mkdirs ();
2429 } else {
You can’t perform that action at this time.
0 commit comments