profiling.sampling heatmap reads non-regular and oversized files #153838
Copy link
Copy link
Closed
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-profilingtype-featureA feature request or enhancementA feature request or enhancement
Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-profilingtype-featureA feature request or enhancementA feature request or enhancement
Activity
picnixz commentedon Jul 17, 2026
I do not think it is correct. Files may be very huge for very long apps. It is different from the binary file read protection
tonghuaroot commentedon Jul 17, 2026
Good point. Dropped the size cap, kept the
is_file()guard only.pythongh-153838: Verify non-regular sources are never opened
gh-153838: Skip non-regular source files in the heatmap exporter (#15…
[3.15] gh-153838: Skip non-regular source files in the heatmap export…
Revert "[3.15] pythongh-153838: Skip non-regular source files in the …
[3.15] Restore deferred backports for 3.15.1, including GH-158874 (#1…