Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-84907

Backup: Incorrect regex for CTRL characters cleaning

XMLWordPrintable

    • 2

      We have below regex in Moodle backup code to clean the CTRL characters

      /[\x-\x8\xb-\xc\xe-\x1f\x7f]/is 

      But in PHP (PCRE), \x is used to define hexadecimal escape sequences (e.g.: \x00 for NUL), and \x- is incorrect since - is not a valid hexadecimal digit.

      This broke the backup/restore process in Moodle with the latest PHP versions. Example: 8.2.28 and 8.3.19

      They might include PCRE library version: 10.45 2025-02-05. This PCRE introduces a breaking change:

      https://github.com/PCRE2Project/pcre2/blob/master/ChangeLog#L119

      We can see the error by running

      vendor/bin/phpunit --filter test_restore_controller_is_executing 

      Error

      1) core_backup\controller_test::test_restore_controller_is_executing
      restore_controller_exception: error/restore_unknown_restore_type
      $a contents: 

      I used XDebug and PPHPUnit to find out the root cause, below is the extra error

      preg_replace(): Compilation failed: digits missing after \x or in \x{} or \o{} or \N{U+} at offset 3 

            huongn@moodle.com Huong Nguyen
            huongn@moodle.com Huong Nguyen
            Meirza Meirza
            Jun Pataleta Jun Pataleta
            Kim Jared Lucas Kim Jared Lucas
            Votes:
            2 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 day, 25 minutes
                1d 25m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.