Hi,

I believe that there is a small bug in GDir's Windows implementation, if called on a directory that does not exist and you then try to enumerate its entries (getNextEntry()).

Basically GDir was storing the return value of its call to FindFirstFile() in GDir::hnd, but using NULL as a sentinel for invalid values, but in fact FindFirstFile() returns INVALID_HANDLE_VALUE (-1).

This patch replaces assignments to NULL with assignments to INVALID_HANDLE_VALUE and all checks now check against INVALID_HANDLE_VALUE instead of NULL.

So if you are ever using poppler on Windows and your app suddenly crashes (which I was only able to do by compiling with all the debugging options turned on, otherwise I only got funny entries in my log like "Error: Couldn't open 'nameToUnicode' file 'D:\kde-mingw\share\poppler\nameToUnicode\{„žYø!'") this may be why.

You know what would also be nice...(would you be open to a patch?) not hardcoding POPPLER_DATADIR, since especially on Windows you never know where it will be installed.

I hope this helps (and I hope I did everything properly...),

-Adam Batkin
diff --git a/goo/gfile.cc b/goo/gfile.cc
index 24ff63f..f6b3c16 100644
--- a/goo/gfile.cc
+++ b/goo/gfile.cc
@@ -657,9 +657,9 @@ GDir::GDir(char *name, GBool doStatA) {
 GDir::~GDir() {
   delete path;
 #if defined(WIN32)
-  if (hnd) {
+  if (hnd != INVALID_HANDLE_VALUE) {
     FindClose(hnd);
-    hnd = NULL;
+    hnd = INVALID_HANDLE_VALUE;
   }
 #elif defined(ACORN)
 #elif defined(MACOS)
@@ -673,11 +673,13 @@ GDirEntry *GDir::getNextEntry() {
   GDirEntry *e;
 
 #if defined(WIN32)
-  if (hnd) {
+  if (hnd != INVALID_HANDLE_VALUE) {
     e = new GDirEntry(path->getCString(), ffd.cFileName, doStat);
-    if (hnd  && !FindNextFile(hnd, &ffd)) {
+    // Removed the next check for hnd since we just checked it
+    // above and I don't see how it could have changed
+    if (!FindNextFile(hnd, &ffd)) {
       FindClose(hnd);
-      hnd = NULL;
+      hnd = INVALID_HANDLE_VALUE;
     }
   } else {
     e = NULL;
@@ -719,7 +721,7 @@ void GDir::rewind() {
 #ifdef WIN32
   GooString *tmp;
 
-  if (hnd)
+  if (hnd != INVALID_HANDLE_VALUE)
     FindClose(hnd);
   tmp = path->copy();
   tmp->append("/*.*");
_______________________________________________
poppler mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/poppler

Reply via email to