zhongjingxiong commented on a change in pull request #35278:
URL: https://github.com/apache/spark/pull/35278#discussion_r802859443
##########
File path: core/src/main/scala/org/apache/spark/util/Utils.scala
##########
@@ -607,6 +609,66 @@ private[spark] object Utils extends Logging {
}
}
+ def unZip(inFile: File, unzipDir: File): Unit = {
+ val zipFile = new ZipFile(inFile)
+ try {
+ val entries = zipFile.getEntries
+ val targetDirPath = unzipDir.getCanonicalPath + File.separator
+ while ({entries.hasMoreElements}) {
+ val entry: ZipArchiveEntry = entries.nextElement
+ if (!entry.isDirectory) {
+ val in = zipFile.getInputStream(entry)
+ try {
+ val file = new File(unzipDir, entry.getName)
+ if (!file.getCanonicalPath.startsWith(targetDirPath)) {
+ throw new IOException(
+ "expanding " + entry.getName + " would create file outside of
" + unzipDir
+ )
+ }
+ if (!file.getParentFile.mkdirs && !file.getParentFile.isDirectory)
{
+ throw new IOException("Mkdirs failed to create " +
file.getParentFile.toString)
+ }
+
+ val out = Files.newOutputStream(file.toPath)
+ try {
+ val buffer = new Array[Byte](8192)
+ var len = 0
+ while ({len = in.read(buffer); len} != -1) {
+ out.write(buffer, 0, len)
+ }
+ }
+ finally {
+ out.close()
+ if (entry.getPlatform == ZipArchiveEntry.PLATFORM_UNIX) {
Review comment:
Here, if the file has permission settings before decompression, we will
set the permission back after decompressing the file.@LuciferYang @Yikf I think
this has really circumvented a lot of non-UNIX situations.Can you review this
code?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]