Fix infinite loop when phancap tries to capture itself capturing itself
authorChristian Weiske <cweiske@cweiske.de>
Wed, 29 Jun 2016 05:11:54 +0000 (07:11 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Wed, 29 Jun 2016 05:11:54 +0000 (07:11 +0200)
src/phancap/Config.php
www/get.php
www/infinite.png [new file with mode: 0644]

index e45f08b..4c0617e 100644 (file)
@@ -234,7 +234,7 @@ class Config
      * @return string Directory of URL without trailing slash,
      *                and without .phar file
      */
-    protected function getCurrentUrlDir()
+    public function getCurrentUrlDir()
     {
         $url = $this->getCurrentUrl();
         $url = preg_replace('/\?.*$/', '', $url);
index f78c3b5..694b843 100644 (file)
@@ -46,6 +46,15 @@ try {
     exit(1);
 }
 
+if (strpos($_SERVER['HTTP_USER_AGENT'], ' cutycapt ') !== false) {
+    //phancap is trying to render a page with an image that
+    // is being fetched from phancap itself, leading to an
+    // infinite loop
+    header('HTTP/1.0 500 Infinite Loop');
+    header('Location: ' . $config->getCurrentUrlDir() . '/infinite.png');
+    exit(3);
+}
+
 $rep = new Repository();
 $rep->setConfig($config);
 try {
diff --git a/www/infinite.png b/www/infinite.png
new file mode 100644 (file)
index 0000000..2327d75
Binary files /dev/null and b/www/infinite.png differ