aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools
diff options
context:
space:
mode:
authorGravatar Klaus Aehlig <aehlig@google.com>2018-01-29 07:51:10 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-01-29 07:52:43 -0800
commit79ebb32e77f134e2f6496dd532bf9574d4198676 (patch)
treec131d52e525b8e0be932dd349620c51c64699715 /src/main/java/com/google/devtools
parent9f2a855be500f6a3bc11f1129600b07265a91f7e (diff)
Support symlinks in external zip archives
Allow symbolic links in zip archives, as long as they refer to a file within the same archive. Fixes #2656. Change-Id: I0b21b8bb79a7e999ef191baa2a71d29745ac65e4 PiperOrigin-RevId: 183664725
Diffstat (limited to 'src/main/java/com/google/devtools')
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/repository/ZipDecompressor.java9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/ZipDecompressor.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/ZipDecompressor.java
index e9d0566247..71d26fcc55 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/ZipDecompressor.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/ZipDecompressor.java
@@ -127,8 +127,13 @@ public class ZipDecompressor implements Decompressor {
PathFragment target = PathFragment.create(new String(buffer, Charset.defaultCharset()))
.normalize();
if (!target.isNormalized()) {
- throw new IOException("Zip entries cannot refer to files outside of their directory: "
- + reader.getFilename() + " has a symlink to " + target);
+ PathFragment pointsTo =
+ PathFragment.create(strippedRelativePath.getParentDirectory(), target).normalize();
+ if (!pointsTo.isNormalized()) {
+ throw new IOException("Zip entries cannot refer to files outside of their directory: "
+ + reader.getFilename() + " has a symlink " + strippedRelativePath + " pointing to "
+ + target);
+ }
}
if (target.isAbsolute()) {
target = target.relativeTo(PathFragment.ROOT_DIR);