Title: Interval.range() hangs forever on a zero (or wrong-sign) step · Issue #1080 · python-pendulum/pendulum · GitHub
Open Graph Title: Interval.range() hangs forever on a zero (or wrong-sign) step · Issue #1080 · python-pendulum/pendulum
X Title: Interval.range() hangs forever on a zero (or wrong-sign) step · Issue #1080 · python-pendulum/pendulum
Description: Affected version: confirmed on release v3.3.0, commit e06dacedc4cdea90fa1286b3965d180ab94cf251. Summary Interval.range(unit, amount) accepts any integer amount, including 0, without validation. Because the loop's advance step and its ter...
Open Graph Description: Affected version: confirmed on release v3.3.0, commit e06dacedc4cdea90fa1286b3965d180ab94cf251. Summary Interval.range(unit, amount) accepts any integer amount, including 0, without validation. Bec...
X Description: Affected version: confirmed on release v3.3.0, commit e06dacedc4cdea90fa1286b3965d180ab94cf251. Summary Interval.range(unit, amount) accepts any integer amount, including 0, without validation. Bec...
Opengraph URL: https://github.com/python-pendulum/pendulum/issues/1080
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Interval.range() hangs forever on a zero (or wrong-sign) step","articleBody":"Affected version: confirmed on release `v3.3.0`, commit `e06dacedc4cdea90fa1286b3965d180ab94cf251`.\n\n## Summary\n\n`Interval.range(unit, amount)` accepts any integer `amount`, including `0`, without validation. Because the loop's advance step and its termination check both depend on `amount`, an `amount` of `0` produces a generator that yields the same starting value forever and never reaches its stated end. Any caller that consumes the generator without an independent bound (a plain `for` loop, `list(...)`, or similar) hangs indefinitely, consuming CPU with no progress, until something external kills the process.\n\n## Details\n\n`src/pendulum/interval.py`:\n\n```python\ndef range(self, unit: str, amount: int = 1) -> Iterator[_T]:\n method = \"add\"\n op = operator.le\n if not self._absolute and self.invert:\n method = \"subtract\"\n op = operator.ge\n\n start, end = self.start, self.end\n\n i = amount\n while op(start, end):\n yield start\n\n start = getattr(self.start, method)(**{unit: i})\n\n i += amount\n```\n\nWhen `amount == 0`:\n- `i` starts at `0` and `i += amount` keeps it at `0` on every iteration.\n- `start = self.start.add(**{unit: i})` recomputes the same value as `self.start` every time, since the added quantity is always `0`.\n- The loop condition `op(start, end)` (effectively `start \u003c= end`) stays true forever, because `start` never advances past `end`.\n\nThe function is a public method on `Interval`/`Period` objects (`pendulum.interval(start, end).range(unit, amount)`), documented as part of the library's date-range iteration API, with no stated restriction that `amount` must be non-zero.\n\n## Steps To Reproduce\n\n(available upon request)\n\n## Impact\n\nA caller that builds a date range from a step value it does not fully control (a configuration field, a query parameter, a value derived from user input) and passes it to `Interval.range()` can be made to hang indefinitely on `amount=0`, consuming a full CPU core with no progress and no way to recover short of killing the worker from outside. This is a realistic pattern: date-range \"step\"/\"interval\" parameters are commonly user- or config-driven (reporting tools, scheduling/trading-strategy libraries that iterate a period at a configurable interval, etc). A related but distinct case, a wrong-sign `amount` on an interval whose direction it does not match (e.g. `amount=-1` on a forward interval), does not hang but instead runs away unbounded in the opposite direction from the stated end, the same missing-validation root cause producing unbounded resource consumption rather than a hang.\n\nSuggested fix: reject `amount == 0` with a `ValueError`, and either require the sign of `amount` to match the interval's direction or normalize it automatically, with regression tests covering both the zero-step and wrong-sign-step cases.\n","author":{"url":"https://github.com/carfeii","@type":"Person","name":"carfeii"},"datePublished":"2026-11-02T14:35:53Z","url":"https://github.com/python-pendulum/pendulum/issues/1080"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:778e4b75-71a8-ef09-abc1-256df166d987 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A34E:3D1C6E:10D667:17C9FB:6B0464BE |
| html-safe-nonce | 7edcc9118e5940071b0ad29fae730833b162ca7a4367ed959fe558190012bf92 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMzRFOjNEMUM2RToxMEQ2Njc6MTdDOUZCOjZCMDQ2NEJFIiwidmlzaXRvcl9pZCI6IjQ1NDA5MDM5NzAzMjE0NjExMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 22b3ca21a3c9a00f58a2ec69963ef294733b12d8afb20032f024ad89bf33824b |
| hovercard-subject-tag | issue:6164640430 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python-pendulum/pendulum/1080/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9c60c4fe1ecf9b0d32156c2be9516f08596715f03ddf611cbb707b41d61a3f57/python-pendulum/pendulum/issues/1080 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9c60c4fe1ecf9b0d32156c2be9516f08596715f03ddf611cbb707b41d61a3f57/python-pendulum/pendulum/issues/1080 |
| og:image:alt | Affected version: confirmed on release v3.3.0, commit e06dacedc4cdea90fa1286b3965d180ab94cf251. Summary Interval.range(unit, amount) accepts any integer amount, including 0, without validation. Bec... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | carfeii |
| hostname | github.com |
| expected-hostname | github.com |
| None | 2d58451b4bcb73c33c67bfb6b28fb75fe6d5e279daf9b560fa4fd832f3d8c9a6 |
| turbo-cache-control | no-preview |
| go-import | github.com/python-pendulum/pendulum git https://github.com/python-pendulum/pendulum.git |
| octolytics-dimension-user_id | 191041900 |
| octolytics-dimension-user_login | python-pendulum |
| octolytics-dimension-repository_id | 62095504 |
| octolytics-dimension-repository_nwo | python-pendulum/pendulum |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 62095504 |
| octolytics-dimension-repository_network_root_nwo | python-pendulum/pendulum |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 03e114520787ad27289207f153520ef97461127c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width