Skip to content

Harmonize extension code checks in pickle #123431

@serhiy-storchaka

Description

@serhiy-storchaka

The C implementation of pickle checks (partially explicitly, partially implicitly) the type and the range of the value returned by the extension registry. These checks are redundant in normal circumstances, because it is already checked in copyreg.add_extension() which is the only public interface for registering an extension. It is still worth to have some checks in the C code to prevent crash, undefined behavior or producing incorrect output in improbable situation (realistically, this can happen only if you broke the extension registry).

The Python implementation does not have explicit check. Broken extension registry will cause errors (with different type and message, but this is not important), except one case -- the code with the false boolean value (0, None, (), etc) -- in that case it produces output. Although, there is a difference when the code has __index__ method but is not int.

The following PR makes both implementations raising exception in the same circumstances (although the type of the exception may be different). The C checks are simplified. The Python check made more reliable.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixes3.13bugs and security fixes3.14bugs and security fixesextension-modulesC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directory

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions