@Override public boolean startsWith(String other) { return delegate.startsWith(other); }
public static boolean isSameOrChildPath( Path parent, Path candidate ) { Path normalizedCandidate = candidate.normalize(); Path normalizedParent = parent.normalize(); return normalizedCandidate.startsWith( normalizedParent ); }
public boolean isPrimaryDex(File dexFile) { Path dexFilePath = dexFile.toPath(); Path parentPath = config.mTempUnzipOldDir.toPath(); if (!dexFilePath.startsWith(parentPath)) { parentPath = config.mTempUnzipNewDir.toPath(); } return DexFormat.DEX_IN_JAR_NAME.equals(parentPath.relativize(dexFilePath).toString().replace('\\', '/')); } }
private static void verifyInsideTargetDirectory(ZipEntry entry, Path entryPath, Path targetDirNormalizedPath) { if (!entryPath.normalize().startsWith(targetDirNormalizedPath)) { // vulnerability - trying to create a file outside the target directory throw new IllegalStateException("Unzipping an entry outside the target directory is not allowed: " + entry.getName()); } }
@Implementation(minSdk = KITKAT) protected static String getStorageState(File directory) { Path directoryPath = directory.toPath(); for (Map.Entry<Path, String> entry : storageState.entrySet()) { if (directoryPath.startsWith(entry.getKey())) { return entry.getValue(); } } return null; }
@Implementation(minSdk = LOLLIPOP) protected static String getExternalStorageState(File directory) { Path directoryPath = directory.toPath(); for (Map.Entry<Path, String> entry : storageState.entrySet()) { if (directoryPath.startsWith(entry.getKey())) { return entry.getValue(); } } return null; }
/** * A check if a file path is a descendant of a parent path * @param forParent the parent the child should be a descendant of * @param potentialChild the path to check * @return true if so * @throws IOException for invalid paths * @since 2.80 * @see InvalidPathException */ public static boolean isDescendant(File forParent, File potentialChild) throws IOException { Path child = fileToPath(potentialChild.getAbsoluteFile()).normalize(); Path parent = fileToPath(forParent.getAbsoluteFile()).normalize(); return child.startsWith(parent); }
public static void validateZipOutputFile( String sourceFilename, final File outFile, final File outDir ) throws IOException { // check for evil zip exploit that allows writing output to arbitrary directories final File canonicalOutFile = outFile.getCanonicalFile(); final String canonicalOutDir = outDir.getCanonicalPath(); if (!canonicalOutFile.toPath().startsWith(canonicalOutDir)) { throw new ISE( "Unzipped output path[%s] of sourceFile[%s] does not start with outDir[%s].", canonicalOutFile, sourceFilename, canonicalOutDir ); } }
public static String getRelativePath(File root, File f) { Path fPath = f.toPath().toAbsolutePath(); Path rootPath = root.toPath().toAbsolutePath(); if (fPath.startsWith(rootPath)) { return rootPath.relativize(fPath).toString(); } else { throw new IllegalStateException(fPath + " must be located inside " + rootPath); } }
@Override public boolean accept( File file ) { Path path = file.toPath(); if ( !path.toAbsolutePath().startsWith( indexRoot ) ) { // This file isn't even under the schema/index root directory return false; } Path schemaPath = indexRoot.relativize( path ); int nameCount = schemaPath.getNameCount(); // - schema/index/lucene/..... boolean isPureLuceneProviderFile = nameCount >= 1 && schemaPath.getName( 0 ).toString().equals( "lucene" ); // - schema/index/lucene_native-x.y/<indexId>/lucene-x.y/x/..... boolean isFusionLuceneProviderFile = nameCount >= 3 && schemaPath.getName( 2 ).toString().startsWith( "lucene-" ); return !isPureLuceneProviderFile && !isFusionLuceneProviderFile; } }
public static boolean isSameOrChildFile( File parent, File candidate ) { Path canonicalCandidate = canonicalPath( candidate ); Path canonicalParentPath = canonicalPath( parent ); return canonicalCandidate.startsWith( canonicalParentPath ); }
/** * @param path Path to resolve only relative to IGNITE_HOME. * @return Resolved path as file, or {@code null} if path cannot be resolved. * @throws IOException If failed to resolve path. */ public static File resolveIgnitePath(String path) throws IOException { File folder = U.resolveIgnitePath(path); if (folder == null) return null; if (!folder.toPath().toRealPath(LinkOption.NOFOLLOW_LINKS).startsWith(Paths.get(U.getIgniteHome()))) return null; return folder; }
/** * Verify that the supplied file or directory is within the test data directory. * * @param path the path to the file or directory; may not be null * @return true if inside the test data directory, or false otherwise */ public static boolean inTestDataDir(Path path) { Path target = FileSystems.getDefault().getPath(dataDir()).toAbsolutePath(); return path.toAbsolutePath().startsWith(target); } }
public void assertStartsWithRaw(final AssertionInfo info, final Path actual, final Path other) { assertNotNull(info, actual); assertExpectedStartPathIsNotNull(other); if (!actual.startsWith(other)) throw failures.failure(info, shouldStartWith(actual, other)); }
public void assertStartsWith(final AssertionInfo info, final Path actual, final Path start) { assertNotNull(info, actual); assertExpectedStartPathIsNotNull(start); final Path canonicalActual; try { canonicalActual = actual.toRealPath(); } catch (IOException e) { throw new PathsException(FAILED_TO_RESOLVE_ACTUAL_REAL_PATH, e); } final Path canonicalOther; try { canonicalOther = start.toRealPath(); } catch (IOException e) { throw new PathsException(FAILED_TO_RESOLVE_ARGUMENT_REAL_PATH, e); } if (!canonicalActual.startsWith(canonicalOther)) throw failures.failure(info, shouldStartWith(actual, start)); }
public void assertStartsWithRaw(final AssertionInfo info, final Path actual, final Path other) { assertNotNull(info, actual); assertExpectedStartPathIsNotNull(other); if (!actual.startsWith(other)) throw failures.failure(info, shouldStartWith(actual, other)); }
@Test public void testCreateTempDirectoryWithDirectoryBlocking() { FileSystem fs = vertx.fileSystem(); String tempDirectory = fs.createTempDirectoryBlocking(testDir, "project", null); Path path = Paths.get(tempDirectory); assertTrue(Files.exists(Paths.get(tempDirectory))); assertTrue(path.startsWith(testDir)); }
@Test public void testCreateTempFileWithDirectoryBlocking() { FileSystem fs = vertx.fileSystem(); String tempFile = fs.createTempFileBlocking(testDir, "project", ".tmp", null); assertNotNull(tempFile); Path path = Paths.get(tempFile); assertTrue(Files.exists(path)); assertTrue(path.startsWith(testDir)); }
@Test public void testCreateTempDirectoryWithDirectory() { FileSystem fs = vertx.fileSystem(); fs.createTempDirectory(testDir, "project", null, onSuccess(tempDirectory -> { Path path = Paths.get(tempDirectory); assertTrue(Files.exists(path)); assertTrue(path.startsWith(testDir)); complete(); })); await(); }
@Test public void testCreateTempFileWithDirectory() { FileSystem fs = vertx.fileSystem(); fs.createTempFile(testDir, "project", ".tmp", null, onSuccess(tempFile -> { assertNotNull(tempFile); Path path = Paths.get(tempFile); assertTrue(Files.exists(path)); assertTrue(path.startsWith(testDir)); complete(); })); await(); }