Medium

Use of "infinity" as an input to datetime and date fields causes infinite loop in pydantic

  • Disclosed: 13.05.2021
  • Updated: 11.10.2026 13:19

Impact

Passing either 'infinity', 'inf' or float('inf') (or their negatives) to datetime or date fields causes validation to run forever with 100% CPU usage (on one CPU). Patches

Pydantic is be patched with fixes available in the following versions:

v1.8.2
v1.7.4
v1.6.2

All these versions are available on pypi, and will be available on conda-forge soon.

See the changelog for details. Workarounds

If you absolutely can't upgrade, you can work around this risk using a validator to catch these values, brief demo:

from datetime import date from pydantic import BaseModel, validator

class DemoModel(BaseModel): date_of_birth: date

python
@validator('date_of_birth', pre=True)
def skip_infinite_values(cls, v):
    try:
        seconds = float(v)
    except (ValueError, TypeError):
        return v
    else:
        if seconds == float('inf'):
            return date.max
        elif seconds == float('-inf'):
            return date.min
        else:
            return seconds

Note: this is not an ideal solution (in particular you'll need a slightly different function for datetimes), instead of a hack like this you should upgrade pydantic.

If you are not using v1.8.x, v1.7.x or v1.6.x and are unable to upgrade to a fixed version of pydantic, please create an issue requesting a back-port, and we will endeavour to release a patch for earlier versions of pydantic. References

This was fixed in commit 7e83fdd.

Affected software

Click a technology to see all vulnerabilities affecting it.

PlatformPackageVulnerable versionsFixed in
Python (PyPI) pydantic < 1.6.2, >= 1.8, < 1.8.2, >= 1.7, < 1.7.4 1.6.2, 1.8.2, 1.7.4

References

CVSS score 3.3/10
CVSS vector
CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:L
Weakness (CWE)
CWE-835
Platform
Python (PyPI)
Package
pydantic
Disclosed
13.05.2021
Updated
11.10.2026 13:19

Sources and licenses

OSV / GitHub Advisory Database - PYSEC-2021-47 - PyPA Advisory Database; CC BY 4.0

OSV / GitHub Advisory Database - GHSA-5jqp-qgf6-3pvh - CC BY 4.0

Vulnerability history: pydantic

All published vulnerabilities of this package (Python (PyPI)), newest first. Shows whether this is a one-off slip or a package that needs watching.

Total entries
2
First → latest
05.2021 04.2024
Without a fix
0
Exploited in attacks
0

Severity breakdown

  • Medium 2

Disclosures per year

  1. 2021: 1
  2. 2022: 0
  3. 2023: 0
  4. 2024: 1
  5. 2025: 0
  6. 2026: 0
  1. Medium · 5.9 CVE-2024-3772 >= 2.0.0, < 2.4.0, < 1.10.13 2.4.0, 1.10.13
  2. Use of "infinity" as an input to datetime and date fields causes infinite loop in pydantic this entry
    Medium · 3.3 CVE-2021-29510 < 1.6.2, >= 1.8, < 1.8.2, >= 1.7, < 1.7.4 1.6.2, 1.8.2, 1.7.4

Know which vulnerabilities affect your application

With the DockRay integration and software inventory enabled, DockRay checks reported component versions against known vulnerabilities and notifies you about confirmed matches. Coverage depends on the supported technology and available advisory data.

Connect your application
DockRay newsletter

Application security in your inbox

Important vulnerabilities, actionable guidance and practical advice for your applications. Choose your technologies and follow what matters to your project.

  • A daily digest of new vulnerabilities, critical ones included.
  • Notifications about important updates.
  • Practical advice on application security and monitoring.

Leave empty to receive updates for every technology.

Free to subscribe. Unsubscribe with one click in any email.