From 39f9a7bf597c07be6cee65f60bec1fb33e04bbf0 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Wed, 29 Jun 2016 07:11:54 +0200 Subject: [PATCH] Fix infinite loop when phancap tries to capture itself capturing itself --- src/phancap/Config.php | 2 +- www/get.php | 9 +++++++++ www/infinite.png | Bin 0 -> 148 bytes 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 www/infinite.png diff --git a/src/phancap/Config.php b/src/phancap/Config.php index e45f08b..4c0617e 100644 --- a/src/phancap/Config.php +++ b/src/phancap/Config.php @@ -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); diff --git a/www/get.php b/www/get.php index f78c3b5..694b843 100644 --- a/www/get.php +++ b/www/get.php @@ -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 index 0000000000000000000000000000000000000000..2327d75f69b58822f961b449647c3e9dbc75c2a3 GIT binary patch literal 148 zcmeAS@N?(olHy`uVBq!ia0vp^DImfCZaseBfc>e% ohoo%^O*X6)Z8gvM{KbKZL9<3=?{xXPjX?bjp00i_>zopr06K;$O#lD@ literal 0 HcmV?d00001 -- 2.30.2