Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catching another infinite loop condition. #350

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,8 @@ ChangeLog
* #345: Auto-detecting more Outlook 365-generated timezone identifiers.
(@jpirkey)
* #348: `FreeBusyGenerator` can now accept streams.
* #329: Infinite loop when using `BYMONTHDAY`, `BYDAY` and/or `BYSETPOS` to
expand a `BYMONTH` rule.


4.1.1 (2016-07-15)
Expand Down
20 changes: 17 additions & 3 deletions lib/Recur/RRuleIterator.php
Expand Up @@ -620,19 +620,33 @@ protected function nextYearly() {

}

$currentMonth = $this->currentDate->format('n');
$currentYear = $this->currentDate->format('Y');
$currentDayOfMonth = $this->currentDate->format('j');
//$currentMonth = $this->currentDate->format('n');
//$currentYear = $this->currentDate->format('Y');
//$currentDayOfMonth = $this->currentDate->format('j');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IF L623-L625 are no longer needed, they should be removed before merging.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha


$advancedToNewMonth = false;

$noOccurrenceCounter = 0;

// If we got a byDay or getMonthDay filter, we must first expand
// further.
if ($this->byDay || $this->byMonthDay) {

while (true) {

$occurrences = $this->getMonthlyOccurrences();
if (!$occurrences) {
// We are counting subsequent months where there weren't
// occurrences. If we exceed the treshold we might be
// dealing with a recurrence rule that doesn't generate
// valid instances.
$noOccurrenceCounter++;
if (++$noOccurrenceCounter > 10) {
throw new InvalidDataException('BYDAY, BYMONTHDAY and/or BYSETPOS rules don\'t generate valid recurrence instances');
}
} else {
$noOccurrenceCounter = 0;
}

foreach ($occurrences as $occurrence) {

Expand Down
39 changes: 39 additions & 0 deletions tests/VObject/Recur/EventIterator/InfiniteLoopProblemTest.php
Expand Up @@ -5,6 +5,7 @@
use DateTimeImmutable;
use DateTimeZone;
use Sabre\VObject\Component\VCalendar;
use Sabre\VObject\Reader;
use Sabre\VObject\Recur;

class InfiniteLoopProblemTest extends \PHPUnit_Framework_TestCase {
Expand Down Expand Up @@ -95,4 +96,42 @@ function testZeroInterval() {

}

/**
* Another infinite loop, from Issue #329.
*
* This was triggered due to a BYMONTHDAY rule that was using a value that
* never occurred in the BYMONTH rule.
*
* This bug surfaced similar issues with BYDAY and BYSETPOS.
*
* @expectedException \Sabre\VObject\InvalidDataException
*/
function testBadByMonthday() {

$input = Reader::read(<<<ICS
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//something//DE
CALSCALE:GREGORIAN
X-WR-TIMEZONE:Europe/Berlin
BEGIN:VEVENT
UID:20160103T123422CET-9863LIMv8E
DTSTAMP:20160103T113422Z
DESCRIPTION:important date
DTSTART;TZID=Europe/Berlin:20151231T000000
DTEND;TZID=Europe/Berlin:20151231T235900
RRULE:FREQ=YEARLY;COUNT=6;BYMONTHDAY=31;BYMONTH=11
SUMMARY:important date
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR
ICS
);
$input->expand(
new DateTimeImmutable('2015-01-01'),
new DateTimeImmutable('2016-01-01')
);

}

}