Skip to content

encodings.search_function() has an unbounded cache #146054

Description

@StanFromIreland

Bug report

Bug description:

Found (accidentally) by our OSS Fuzz fuzzer in #493449985.

The encodings.search_function() caches every codec lookup miss in an unbounded _cache dict, causing memory growth (the fuzzer gathered a 2561Mb cache causing the abort).
I would suggest we bound its size like we do elsewhere (e.g. the struct cache).

Technically, there is the possibility of a DoS vulnerability, however the PSRT decided that it is unrealistic for this to be exploited.

CPython versions tested on:

CPython main branch, 3.15, 3.14, 3.13

Operating systems tested on:

No response

Linked PRs

Activity

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

Metadata

Metadata

Labels

stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions