Moodle
  1. Moodle
  2. MDL-13661

lib/dmllib.php - rcache_set function - array_shift php native function is corrupting cached data

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 1.8.5
    • Fix Version/s: 1.8.5, 1.9
    • Component/s: Libraries, Performance
    • Labels:
      None
    • Environment:
      php > 5.1.2, Apache > 2, windows vista business edition, linux Ubuntu > 6, moodle 2007021541 (1.8.4+)
    • Affected Branches:
      MOODLE_18_STABLE
    • Fixed Branches:
      MOODLE_18_STABLE, MOODLE_19_STABLE
    • Rank:
      30510

      Description

      the cached data are referenced by their ids > $rcache>data[$table][$id], $rcache->data[$table] is an associative array.
      but some php native functions used to manage array data return indexed arrays. This is the case of the array_shift function.

      the new rcache_set function has corrupted some cached data of our moodle making the script to enter in an infinite loop in the lib/accesslib.php - get_parent_cats function.

      the problem is coming from this lines :

      function rcache_set($table, $id, $rec) {
      global $CFG, $MCACHE, $rcache;

      if ($CFG->cachetype === 'internal') {
      if (!isset($rcache->data[$table]))

      { $rcache->data[$table] = array(); }

      if (!isset($rcache->data[$table][$id]) and count($rcache->data[$table]) > $CFG->intcachemax)

      { array_shift($rcache->data[$table]); }

      $rcache->data[$table][$id] = clone($rec);

      to resolve the problem we have to make our own array_shift function or replace the array_shift($rcache->data[$table]); line by something like :

      $keys = array_keys($rcache->data[$table]);
      $firstkey = $keys[0];
      unset($rcache->data[$table][$firstkey]);

      hope that's help

        Issue Links

          Activity

          Hide
          Petr Škoda added a comment -

          eh, sorry - my fault, the 1.8.4+ and above are affected

          Show
          Petr Škoda added a comment - eh, sorry - my fault, the 1.8.4+ and above are affected
          Hide
          Petr Škoda added a comment -

          fixed similar problem is static format_text() cron cache,
          big thanks for spotting of this silly bug!!

          Show
          Petr Škoda added a comment - fixed similar problem is static format_text() cron cache, big thanks for spotting of this silly bug!!
          Hide
          Petr Škoda added a comment -

          btw in 1.9 the rcache should not be needed anymore

          Show
          Petr Škoda added a comment - btw in 1.9 the rcache should not be needed anymore

            People

            • Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: