Skip to content

profiling.sampling heatmap reads non-regular and oversized files #153838

Description

@tonghuaroot

Bug description

The heatmap exporter in profiling.sampling reads source files named in a profile unconditionally via Path(filename).read_text(). It does not check whether the path is a regular file or whether the file size is reasonable.

When replaying a binary profile, a filename pointing to a device file (e.g. /dev/zero) causes unbounded memory growth. An oversized file has the same effect.

The fix adds an is_file() guard and a 10 MB size cap before reading, consistent with the binary reader hardening in gh-152718.

CPython versions tested on

main

Operating systems tested on

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-profilingtype-featureA feature request or enhancement

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions