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


##########
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:
   Hmm, ok but by using `target/sub/..` as output dir it does not cover the 
case anymore that I mentioned. Because then the test would most likely still 
succeed even if the implementation erroneously just used `normalize()` without 
`toRealPath()` or `toAbsolutePath()`.
   
   To cover this, I think you would really need `Path.of("..")` (without any 
parent directory). But that would indeed not be ideal for this test here. Maybe 
at least the failing case could be covered though, where it is expected that an 
exception is thrown and no files or directories are created. And maybe give the 
escaping file a distinct name (e.g. `../commons-compress-escape.txt`) so that 
if the test unexpectedly fails and escape happens, the developer does not 
wonder about random files in the parent directory.
   
   Not sure though if that would be a clean enough solution.



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