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 e45f08b38042c7ff9f9dab36cc22517775a51e8c..4c0617ecc9867c7f6f867f10502a81d88c12fdf0 100644 (file)
@@ -234,7 +234,7 @@ class Config
      * @return string Directory of URL without trailing slash,
      *                and without .phar file
      */
      * @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);
     {
         $url = $this->getCurrentUrl();
         $url = preg_replace('/\?.*$/', '', $url);
index f78c3b5fef988653694e4c88d517d663f5e48b84..694b843173b88b67357abc4c88b8ac165263201c 100644 (file)
@@ -46,6 +46,15 @@ try {
     exit(1);
 }
 
     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 {
 $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