Skip to content

GHSA-5jqp-qgf6-3pvh CVE-2021-29510 PYSEC-2021-47

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

Medium PyPI
Severity
5.3 / 10
Medium · CVSS 4.0
Exploit chance (EPSS)
0.97%
Chance of exploitation in the next 30 days. Higher than 62.10% of scored vulnerabilities.
Known exploited
No
Not in CISA's catalog
Weakness
CWE-835 Loop with Unreachable Exit Condition ('Infinite Loop')
Fix
1.6.2
Upgrade pydantic to this version or later

Description

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

@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 versions

PyPI

PackageVulnerableFixed in
pydantic
< 1.6.2
1.6.2
pydantic
>= 1.8, < 1.8.2
1.8.2
pydantic
>= 1.7, < 1.7.4
1.7.4
pydantic
< 1.6.2
1.6.2
pydantic
>= 1.8, < 1.8.2
1.8.2
pydantic
>= 1.7, < 1.7.4
1.7.4
pydantic
< 1.6.2
>= 1.7, < 1.7.4
>= 1.8, < 1.8.2
1.6.2
1.7.4
1.8.2

How to fix

Move to the fixed version or later with your package manager, update the lockfile, and run your tests. If the package only arrives through another dependency, upgrade that dependency first. If none of its releases pulls a fixed version yet, force the version with your package manager's override.

pydantic PyPI → 1.6.2

pip
pip install --upgrade "pydantic>=1.6.2"
poetry
poetry add "pydantic>=1.6.2"
uv
uv add "pydantic>=1.6.2"

Severity breakdown

CVSS 4.0 5.3

CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N

Attack vector
Network
Attack complexity
Low
Attack requirements
None
Privileges required
None
User interaction
Passive
Confidentiality (vulnerable system)
None
Integrity (vulnerable system)
None
Availability (vulnerable system)
Low
Confidentiality (subsequent systems)
None
Integrity (subsequent systems)
None
Availability (subsequent systems)
None

CVSS 3.1 3.3

CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:L

Attack vector
Local
Attack complexity
Low
Privileges required
None
User interaction
Required
Scope
Unchanged
Confidentiality
None
Integrity
None
Availability
Low

Weakness

CWE-835: Loop with Unreachable Exit Condition ('Infinite Loop')

The product contains an iteration or loop with an exit condition that cannot be reached, i.e., an infinite loop.

References

Timeline

  1. Published
  2. Last updated by the source
  3. Latest EPSS score
AdvisorySeverityWhy it's related
GHSA-mr82-8j83-vxmv
Pydantic regular expression denial of service
High Also affects pydantic
GHSA-5849-834g-hvw5
pypdf has possible infinite loop when hitting EOF in standard xref table during trailer search
High Same weakness, CWE-835
GHSA-mfr5-77xh-9j7h
pypdf has possible infinite loop when cloning dictionaries
High Same weakness, CWE-835
GHSA-h6cr-wjv9-3cpp
Forge: Denial of Service via infinite loop in BigInteger.modInverse() with negative input (incomplete fix of CVE-2026-33891)
Low Same weakness, CWE-835
GHSA-fw5c-8223-6h42
russh: peer-declared zero maximum packet size permanently stalls channel writes (silent AsyncWrite hang)
Medium Same weakness, CWE-835
EEF-CVE-2026-115269
HTTP/2 WINDOW_UPDATE and SETTINGS frames reset the request body read timeout in Bandit
Not rated yet Same weakness, CWE-835
GHSA-3j72-p6qg-6xp7
Pillow: TarIO negative size field causes infinite CPU-spin loop
Medium Same weakness, CWE-835
GHSA-39mj-jf6j-2qj3
pypdf: Possible infinite loop when hitting EOF in standard xref table
Medium Same weakness, CWE-835

Credits: bluetech, nina-j

Is this in your code?

MergeHarbor checks every repository's dependencies against this database, ranks what matters by exploitability and reachability, routes it to the owning team and opens the fix pull request.

Check your repos with MergeHarbor