El mar, 30-06-2009 a las 23:12 +0200, Albert Astals Cid escribió:
> Hi, file on bug 22551 is failing on getFileSpecNameForPlatform
> 
>   if (fileSpec->isDict()) {
> #ifdef WIN32
>     if (!fileSpec->dictLookup("DOS", &obj1)->isString()) {
> #else
>     if (!fileSpec->dictLookup("Unix", &obj1)->isString()) {
> #endif
>       obj1.free();
>       if (fileSpec->dictLookup("UF", &obj1)->isString ()) {
>         name = obj1.getString()->copy();
>       } else if (fileSpec->dictLookup("F", &obj1)->isString ()) {
>         name = obj1.getString()->copy();
>       } else {
>         error(-1, "Illegal file spec in link");
>       }
>     }
>     obj1.free();
> 
>   // error
>   } else {
>     error(-1, "Illegal file spec in link");
>   }
> 
> The thing is that i seem to miss a else here, i mean if Unix is not found we 
> use UF or F, but if Unix is found shouldn't we do
>  name = obj1.getString()->copy();

you are right.

> Carlos i think this code is yours, is it a typo/bug or am i missing something?

Attached patch should fix the problem. It also makes that code little
bit easier to read. 

> Albert
> _______________________________________________
> poppler mailing list
> [email protected]
> http://lists.freedesktop.org/mailman/listinfo/poppler


-- 
Carlos Garcia Campos
PGP key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x523E6462
From 5a45e6f5943cd8c400981b029802f20bd8cccb14 Mon Sep 17 00:00:00 2001
From: Carlos Garcia Campos <[email protected]>
Date: Wed, 1 Jul 2009 11:43:05 +0200
Subject: [PATCH] Do not use F and UF entries if Unix or DOS are present in FileSpec dict

---
 poppler/FileSpec.cc |  112 +++++++++++++++++++++++----------------------------
 1 files changed, 50 insertions(+), 62 deletions(-)

diff --git a/poppler/FileSpec.cc b/poppler/FileSpec.cc
index 07a5ed8..68bca23 100644
--- a/poppler/FileSpec.cc
+++ b/poppler/FileSpec.cc
@@ -63,84 +63,72 @@ GBool getFileSpecNameForPlatform (Object *fileSpec, Object *fileName)
     return gTrue;
   }
 
-  Object obj1;
-  GooString *name;
-
-  name = NULL;
-  
   if (fileSpec->isDict()) {
 #ifdef WIN32
-    if (!fileSpec->dictLookup("DOS", &obj1)->isString()) {
+    fileSpec->dictLookup("DOS", fileName);
 #else
-    if (!fileSpec->dictLookup("Unix", &obj1)->isString()) {
+    fileSpec->dictLookup("Unix", fileName);
 #endif
-      obj1.free();
-      if (fileSpec->dictLookup("UF", &obj1)->isString ()) {
-        name = obj1.getString()->copy();
-      } else if (fileSpec->dictLookup("F", &obj1)->isString ()) {
-        name = obj1.getString()->copy();
-      } else {
-        error(-1, "Illegal file spec in link");
+    if (!fileName->isString()) {
+      fileName->free();
+      if (!fileSpec->dictLookup("UF", fileName)->isString ()) {
+        fileName->free();
+        if (!fileSpec->dictLookup("F", fileName)->isString ()) {
+	  fileName->free();
+	  error(-1, "Illegal file spec");
+	  return gFalse;
+	}
       }
     }
-    obj1.free();
-
-  // error
   } else {
-    error(-1, "Illegal file spec in link");
+    error(-1, "Illegal file spec");
+    return gFalse;
   }
 
   // system-dependent path manipulation
-  if (name) {
 #ifdef WIN32
-    int i, j;
-
-    // "//...."             --> "\...."
-    // "/x/...."            --> "x:\...."
-    // "/server/share/...." --> "\\server\share\...."
-    // convert escaped slashes to slashes and unescaped slashes to backslashes
-    i = 0;
-    if (name->getChar(0) == '/') {
-      if (name->getLength() >= 2 && name->getChar(1) == '/') {
-	name->del(0);
-	i = 0;
-      } else if (name->getLength() >= 2 &&
-		 ((name->getChar(1) >= 'a' && name->getChar(1) <= 'z') ||
-		  (name->getChar(1) >= 'A' && name->getChar(1) <= 'Z')) &&
-		 (name->getLength() == 2 || name->getChar(2) == '/')) {
-	name->setChar(0, name->getChar(1));
-	name->setChar(1, ':');
-	i = 2;
-      } else {
-	for (j = 2; j < name->getLength(); ++j) {
-	  if (name->getChar(j-1) != '\\' &&
-	      name->getChar(j) == '/') {
-	    break;
-	  }
-	}
-	if (j < name->getLength()) {
-	  name->setChar(0, '\\');
-	  name->insert(0, '\\');
-	  i = 2;
+  int i, j;
+  GooString *name = fileName->getString();
+  // "//...."             --> "\...."
+  // "/x/...."            --> "x:\...."
+  // "/server/share/...." --> "\\server\share\...."
+  // convert escaped slashes to slashes and unescaped slashes to backslashes
+  i = 0;
+  if (name->getChar(0) == '/') {
+    if (name->getLength() >= 2 && name->getChar(1) == '/') {
+      name->del(0);
+      i = 0;
+    } else if (name->getLength() >= 2 &&
+	       ((name->getChar(1) >= 'a' && name->getChar(1) <= 'z') ||
+		(name->getChar(1) >= 'A' && name->getChar(1) <= 'Z')) &&
+	       (name->getLength() == 2 || name->getChar(2) == '/')) {
+      name->setChar(0, name->getChar(1));
+      name->setChar(1, ':');
+      i = 2;
+    } else {
+      for (j = 2; j < name->getLength(); ++j) {
+        if (name->getChar(j-1) != '\\' &&
+	    name->getChar(j) == '/') {
+	  break;
 	}
       }
-    }
-    for (; i < name->getLength(); ++i) {
-      if (name->getChar(i) == '/') {
-	name->setChar(i, '\\');
-      } else if (name->getChar(i) == '\\' &&
-		 i+1 < name->getLength() &&
-		 name->getChar(i+1) == '/') {
-	name->del(i);
+      if (j < name->getLength()) {
+        name->setChar(0, '\\');
+	name->insert(0, '\\');
+	i = 2;
       }
     }
-#else
-    // no manipulation needed for Unix
-#endif
-  } else {
-    return gFalse;
   }
+  for (; i < name->getLength(); ++i) {
+    if (name->getChar(i) == '/') {
+      name->setChar(i, '\\');
+    } else if (name->getChar(i) == '\\' &&
+	       i+1 < name->getLength() &&
+	       name->getChar(i+1) == '/') {
+      name->del(i);
+    }
+  }
+#endif /* WIN32 */
 
-  fileName->initString (name);
   return gTrue;
 }
-- 
1.6.0.4

Attachment: signature.asc
Description: Esta parte del mensaje está firmada digitalmente

_______________________________________________
poppler mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/poppler

Reply via email to