Skip to content

Commit 1033d94

Browse files
committed
PDFBOX-5660: skip different directory
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1931439 13f79535-47bb-0310-9956-ffa450edef68
1 parent 605865c commit 1033d94

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ExtractEmbeddedFiles.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static void main( String[] args ) throws IOException
6161
}
6262

6363
File pdfFile = new File(args[0]);
64-
String directoryPath = pdfFile.getParent();
64+
String directoryPath = pdfFile.getParentFile().getCanonicalPath();
6565
try (PDDocument document = Loader.loadPDF(pdfFile))
6666
{
6767
PDDocumentNameDictionary namesDictionary =
@@ -141,6 +141,11 @@ private static void extractFile(String filename, PDEmbeddedFile embeddedFile, St
141141
{
142142
File file = new File(directoryPath, filename);
143143
File parentDir = file.getParentFile();
144+
if (!parentDir.getCanonicalPath().startsWith(directoryPath))
145+
{
146+
System.err.println("Ignoring " + filename + " (different directory)");
147+
return;
148+
}
144149
if (!parentDir.exists())
145150
{
146151
// sometimes paths contain a directory

0 commit comments

Comments
 (0)