]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-6196 infinite loop in header encoding when using some site charsets (gb18030...
authorskodak <skodak>
Thu, 8 Mar 2007 00:05:58 +0000 (00:05 +0000)
committerskodak <skodak>
Thu, 8 Mar 2007 00:05:58 +0000 (00:05 +0000)
lib/textlib.class.php

index d07e751401929107cb3cfb2a789261d465b0660d..61234e8573e084b6696f979a72c17034a4d587d2 100644 (file)
@@ -242,8 +242,14 @@ class textlib {
         $ratio = $this->strlen($text, $charset) / strlen($text);
     /// Base64 ratio
         $magic = $avglength = floor(3 * $length * $ratio / 4);
+    /// basic infinite loop protection
+        $maxiterations = strlen($text)*2;
+        $iteration = 0; 
     /// Iterate over the string in magic chunks
         for ($i=0; $i <= $this->strlen($text, $charset); $i+=$magic) {
+            if ($iteration++ > $maxiterations) {
+                return str_repeat('?', strlen($text)); // probably infinite loop, safer to use raw char length here 
+            } 
             $magic = $avglength;
             $offset = 0;
         /// Ensure the chunk fits in length, reduding magic if necessary