JavaScriptMinifier: Fix "Uninitialized offset" in regexp char class parsing
authorTimo Tijhof <krinklemail@gmail.com>
Wed, 31 Jan 2018 03:55:15 +0000 (19:55 -0800)
committerTimo Tijhof <krinklemail@gmail.com>
Wed, 31 Jan 2018 03:55:15 +0000 (19:55 -0800)
Bug: T75556
Change-Id: I0bb63212dd44aec3c6b40477553dbf6a471bc7b3

includes/libs/JavaScriptMinifier.php
tests/phpunit/includes/libs/JavaScriptMinifierTest.php

index a1a93d2..5ecfc7c 100644 (file)
@@ -498,6 +498,13 @@ class JavaScriptMinifier {
                                        } while ( $end - 2 < $length && $s[$end - 2] === '\\' );
                                        // Correction (1): Undo speculative add, keep only one (end of regexp)
                                        $end--;
+                                       if ( $end > $length ) {
+                                               // Correction (2): Loop wrongly assumed "]" was seen
+                                               // String ended without ending char class or regexp. Correct $end.
+                                               // TODO: This is invalid and should throw.
+                                               $end--;
+                                               break;
+                                       }
                                }
                                // Search past the regexp modifiers (gi)
                                while ( $end < $length && ctype_alpha( $s[$end] ) ) {
index d6a1040..6734976 100644 (file)
@@ -86,6 +86,10 @@ class JavaScriptMinifierTest extends PHPUnit_Framework_TestCase {
                        // FIXME: This is invalid, but currently tolerated
                        [ "*/", "*/", false ],
 
+                       // Cover failure case of incomplete char class in regexp (T75556)
+                       // FIXME: This is invalid, but currently tolerated
+                       [ "/a[b/.test", "/a[b/.test", false ],
+
                        // Cover failure case of incomplete string at end of file (T75556)
                        // FIXME: This is invalid, but currently tolerated
                        [ "'a", "'a", false ],