Index: configure
===================================================================
--- configure	(revision 36298)
+++ configure	(working copy)
@@ -855,6 +855,7 @@
 _priority=no
 def_dos_paths="#define HAVE_DOS_PATHS 0"
 def_stream_cache="#define CONFIG_STREAM_CACHE 1"
+def_path_limit_hack="#define CONFIG_PATH_LIMIT_HACK 0"
 def_priority="#undef CONFIG_PRIORITY"
 def_pthread_cache="#undef PTHREAD_CACHE"
 shmem=no
@@ -1780,6 +1781,7 @@
   _priority=yes
   def_dos_paths="#define HAVE_DOS_PATHS 1"
   def_priority="#define CONFIG_PRIORITY 1"
+  def_path_limit_hack="#define CONFIG_PATH_LIMIT_HACK 1"
 fi

 if wine ; then
@@ -8724,6 +8726,7 @@
 $def_macosx_finder
 $def_maemo
 $def_memalign_hack
+$def_path_limit_hack
 $def_priority
 $def_quicktime
 $def_restrict_keyword
Index: path.c
===================================================================
--- path.c	(revision 36298)
+++ path.c	(working copy)
@@ -26,6 +26,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <limits.h>
 #include "config.h"
 #include "mp_msg.h"
 #include "path.h"
@@ -225,6 +226,8 @@

     if (len == 0)
         return strdup("./");
+    if (CONFIG_PATH_LIMIT_HACK && len >= PATH_MAX)
+        return NULL;
     dirname = malloc(len + 1);
     if (!dirname)
         return NULL;
@@ -254,11 +257,16 @@
 #else
     if (path[0] == '/')
 #endif
-        return strdup(path);
+        return (CONFIG_PATH_LIMIT_HACK && strlen(path) >= PATH_MAX) ?
+               NULL : strdup(path);

     ret = mp_dirname(base);
     if (!ret)
         return NULL;
+    if (CONFIG_PATH_LIMIT_HACK && strlen(ret) + strlen(path) >= PATH_MAX) {
+        free(ret);
+        return NULL;
+    }
     tmp = realloc(ret, strlen(ret) + strlen(path) + 1);
     if (!tmp) {
         free(ret);