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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve validation of intervals? #120

Open
SimonGustavsson opened this issue Mar 9, 2023 · 1 comment
Open

Improve validation of intervals? #120

SimonGustavsson opened this issue Mar 9, 2023 · 1 comment

Comments

@SimonGustavsson
Copy link

Hello 馃憢

Creating a RecurrenceRule with an interval that is just large enough causes IllegalArgumentException.

It looks like this happens here where the interval is multiple with 7 which causes it to overflow to a negative number which the calendar rightly rejects.

I do think lib-recur is doing the right thing rejecting this (it's a silly interval after all), but the exception is very unexpected.

Could/should this be validated a little earlier on and surfaced in a more obvious way perhaps?

Repro steps:

    @Test
    public void itOverflows() throws InvalidRecurrenceRuleException {
        RecurrenceRule rule = new RecurrenceRule("FREQ=WEEKLY;INTERVAL=1000000000", RfcMode.RFC5545_STRICT);
        RecurrenceRuleIterator iterator =
             rule.iterator(1578406277000L, TimeZone.getTimeZone("America/New_York"));
    }

Exception:

java.lang.IllegalArgumentException: n must be >=0
	at org.dmfs.rfc5545.calendarmetrics.NoLeapMonthCalendarMetrics.nextDay(NoLeapMonthCalendarMetrics.java:226)
	at org.dmfs.rfc5545.recur.Freq$3.next(Freq.java:74)
	at org.dmfs.rfc5545.recur.FreqIterator.next(FreqIterator.java:98)
	at org.dmfs.rfc5545.recur.SanityFilter.next(SanityFilter.java:92)
	at org.dmfs.rfc5545.recur.RecurrenceRuleIterator.fetchNextInstance(RecurrenceRuleIterator.java:95)
	at org.dmfs.rfc5545.recur.RecurrenceRuleIterator.<init>(RecurrenceRuleIterator.java:89)
	at org.dmfs.rfc5545.recur.RecurrenceRule.iterator(RecurrenceRule.java:2216)
	at org.dmfs.rfc5545.recur.RecurrenceRule.iterator(RecurrenceRule.java:2140)
@SimonGustavsson SimonGustavsson changed the title Improve validation of intervals Improve validation of intervals? Mar 9, 2023
@dmfs
Copy link
Owner

dmfs commented Mar 11, 2023

I guess the problem goes a bit deeper. The underlying datetime lib stores the year in just 18 bits. There will be an overrun in year 262144. At present I don't consider that an issue. That might change around the year 260000, though. If this lib is still in use by then, people might be worried about this issue. ;-)

I guess it makes sense to validate the interval value and limit it to some reasonable value. Not sure what a reasonable limit would be though. It probably depends on the FREQ value. For starters we could limit the interval to 0<n<10000000. That's probably a reasonable range. For a SECONDLY rule that would be an interval of about 7.6 years.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants