Skip to content
Browse files

MDL-34251 question engine: possible infinite loop loading usages

In the case where either a question_attempt had not steps, or a
question_usage had not question_attempts, the load_from_records methods
could get stuck in an infinite loop.
  • Loading branch information...
1 parent 947ba9c commit b0e0762ca0715b70915e5b0908ba9d98346fe14d @timhunt timhunt committed Jul 17, 2012
Showing with 17 additions and 0 deletions.
  1. +9 −0 question/engine/questionattempt.php
  2. +8 −0 question/engine/questionusage.php
View
9 question/engine/questionattempt.php
@@ -1213,6 +1213,15 @@ public static function load_from_records($records, $questionattemptid,
$qa->behaviour = question_engine::make_behaviour(
$record->behaviour, $qa, $preferredbehaviour);
+ // If attemptstepid is null (which should not happen, but has happened
+ // due to corrupt data, see MDL-34251) then the current pointer in $records
+ // will not be advanced in the while loop below, and we get stuck in an
+ // infinite loop, since this method is supposed to always consume at
+ // least one record. Therefore, in this case, advance the record here.
+ if (is_null($record->attemptstepid)) {
+ $records->next();
+ }
+
$i = 0;
while ($record && $record->questionattemptid == $questionattemptid && !is_null($record->attemptstepid)) {
$qa->steps[$i] = question_attempt_step::load_from_records($records, $record->attemptstepid);
View
8 question/engine/questionusage.php
@@ -706,6 +706,14 @@ public static function load_from_records($records, $qubaid) {
$quba->observer = new question_engine_unit_of_work($quba);
+ // If slot is null then the current pointer in $records will not be
+ // advanced in the while loop below, and we get stuck in an infinite loop,
+ // since this method is supposed to always consume at least one record.
+ // Therefore, in this case, advance the record here.
+ if (is_null($record->slot)) {
+ $records->next();
+ }
+
while ($record && $record->qubaid == $qubaid && !is_null($record->slot)) {
$quba->questionattempts[$record->slot] =
question_attempt::load_from_records($records,

0 comments on commit b0e0762

Please sign in to comment.
Something went wrong with that request. Please try again.