Skip to content

Raise ConfigException on an out-of-range period value - #355

Open
eeshsaxena wants to merge 1 commit into
chimpler:masterfrom
eeshsaxena:fix/period-overflow
Open

Raise ConfigException on an out-of-range period value#355
eeshsaxena wants to merge 1 commit into
chimpler:masterfrom
eeshsaxena:fix/period-overflow

Conversation

@eeshsaxena

Copy link
Copy Markdown

Parsing a config whose value is an absurdly large millisecond period crashes with a raw OverflowError:

>>> from pyhocon import ConfigFactory
>>> ConfigFactory.parse_string('a = 99999999999999999999999 ms')
OverflowError: Python int too large to convert to C int

convert_period does int(tokens.value) on an unbounded digit run, and a millisecond period is built with datetime.timedelta, whose C-level day count overflows. Since get_period_expr() is part of value_expr in the parser, this fires at parse time, so any HOCON string containing such a value takes the whole parse down instead of reporting a config error.

The fix catches the overflow in convert_period and raises ConfigException. Normal periods are unaffected. Added a test in tests/test_periods.py.

A millisecond period is built with datetime.timedelta, whose C-level day count
overflows for an absurdly large value like '99999999999999999999999 ms'. Because
period parsing is wired into value_expr, ConfigFactory.parse_string leaked a raw
OverflowError at parse time. Catch it in convert_period and raise ConfigException
instead.
@eeshsaxena

Copy link
Copy Markdown
Author

Hi! Gentle nudge on this one whenever you have some bandwidth. It's a small, self-contained fix (Raise ConfigException on an out-of-range period value), and it's currently mergeable with no conflicts. No urgency at all, and I'm happy to make any changes you'd like. Thanks for maintaining pyhocon!

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

Successfully merging this pull request may close these issues.

1 participant