Skip to content

MemoryError when calling format_field on a Formatter object #134020

Closed
@gabe-sherman

Description

@gabe-sherman

Bug report

Bug description:

The below code results in a 'MemoryError' being raised in the format_field function.

import string
obj = string.Formatter()
ret = obj.format_field("test", "5555555555550555")

Traceback

Traceback (most recent call last):
  File "rep.py", line 4, in <module>
    ret = obj.format_field("test", "5555555555550555")
  File "/usr/lib/python3.10/string.py", line 235, in format_field
    return format(value, format_spec)
MemoryError

CPython versions tested on:

3.10

Operating systems tested on:

Linux

Activity

StanFromIreland

StanFromIreland commented on May 14, 2025

@StanFromIreland
Contributor

format_field is a wrapper around format

format("test", "5555555555550555")

Is the core problem. Though IMO it is fine, it is a massive width, and would realistically fail, is there even a point to making it more graceful?

sergey-miryanov

sergey-miryanov commented on May 14, 2025

@sergey-miryanov
Contributor

What do you expect? Your format string interpreted as a '5555555555550555s' and tried to allocate string with length of 5555555555550555.

gabe-sherman

gabe-sherman commented on May 14, 2025

@gabe-sherman
Author

Thank you for the responses. This was found while fuzzing the Python interpreter libraries, and I wasn't sure if it represented a true issue. I will close this issue now, as this represents expected behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      MemoryError when calling format_field on a Formatter object · Issue #134020 · python/cpython

      Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

      Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant