tomasilluminati commented on code in PR #776:
URL: https://github.com/apache/commons-compress/pull/776#discussion_r3744624523


##########
src/test/java/org/apache/commons/compress/archivers/extractor/ExtractorRootBoundaryTest.java:
##########
@@ -0,0 +1,178 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.commons.compress.archivers.extractor;
+
+import static 
org.apache.commons.compress.archivers.extractor.Fixtures.Entry.dir;
+import static 
org.apache.commons.compress.archivers.extractor.Fixtures.Entry.file;
+import static 
org.apache.commons.compress.archivers.extractor.Fixtures.Entry.hardlink;
+import static 
org.apache.commons.compress.archivers.extractor.Fixtures.Entry.symlink;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.attribute.BasicFileAttributes;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+/**
+ * Root-boundary invariant: {@code newExtractor} canonicalizes the target with 
{@code toRealPath}, so the containment guard is
+ * not sensitive to how the target is spelled (trailing separator, {@code .} 
component, or a symlinked path). This is why the
+ * extractor uses {@code resolveWithinRoot} against a canonical root rather 
than the lexical {@code ArchiveEntry.resolveIn},
+ * which compares against the parent string as given and misbehaves when that 
parent is not normalized.
+ */
+class ExtractorRootBoundaryTest {

Review Comment:
   Good catch, my test wasn't actually asserting much, normalize() was 
collapsing target/sub/.. upfront, so it passed regardless. I swapped it for a 
bare Paths.get("..") target with an entry named ../commons-compress-escape.txt. 
Confirmed it fails if toRealPath() gets removed, so it's definitely doing its 
job now



-- 
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]

Reply via email to