Title: _remote_debugging: unbounded allocation when a profiling binary file declares oversized table counts · Issue #152718 · python/cpython · GitHub
Open Graph Title: _remote_debugging: unbounded allocation when a profiling binary file declares oversized table counts · Issue #152718 · python/cpython
X Title: _remote_debugging: unbounded allocation when a profiling binary file declares oversized table counts · Issue #152718 · python/cpython
Description: Bug report Bug description The binary profile reader in _remote_debugging (used by python -m profiling.sampling to replay .pyb files) reads the string-table and frame-table entry counts from the file footer and allocates arrays of that s...
Open Graph Description: Bug report Bug description The binary profile reader in _remote_debugging (used by python -m profiling.sampling to replay .pyb files) reads the string-table and frame-table entry counts from the fi...
X Description: Bug report Bug description The binary profile reader in _remote_debugging (used by python -m profiling.sampling to replay .pyb files) reads the string-table and frame-table entry counts from the fi...
Opengraph URL: https://github.com/python/cpython/issues/152718
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"_remote_debugging: unbounded allocation when a profiling binary file declares oversized table counts","articleBody":"# Bug report\n\n## Bug description\n\nThe binary profile reader in `_remote_debugging` (used by `python -m\nprofiling.sampling` to replay `.pyb` files) reads the string-table and\nframe-table entry counts from the file footer and allocates arrays of that size\n*before* validating the counts against the amount of data actually present in\nthe file:\n\n- `reader_parse_string_table` does `PyMem_Calloc(strings_count, sizeof(PyObject *))`\n- `reader_parse_frame_table` does `PyMem_Malloc(frames_count * sizeof(FrameEntry))`\n\n`strings_count` / `frames_count` are 32-bit values taken from the footer, so a\ntiny file can declare up to `2**32 - 1` entries and make the reader attempt a\nmulti-gigabyte allocation (up to ~120 GB for the frame table). Opening the file\nis enough; no valid sample data is required.\n\nThis is reachable from the CLI: `python -m profiling.sampling replay \u003cfile>` and\n`--diff-flamegraph \u003cbaseline>` both open a user-supplied `.pyb` through\n`_remote_debugging.BinaryReader`, and the `replay` input check only validates\nthe magic number, not the footer.\n\n## Reproducer\n\n```python\nimport _remote_debugging, struct, os, tempfile\n\nfn = tempfile.mktemp(suffix=\".pyb\")\nw = _remote_debugging.BinaryWriter(fn, 1000, 0, compression=0)\nw.finalize() # minimal valid file, no samples\nsize = os.path.getsize(fn)\n\n# footer is the last 32 bytes; the frame count is a u32 at footer offset 4\nwith open(fn, \"r+b\") as f:\n f.seek(size - 32 + 4)\n f.write(struct.pack(\"\u003cI\", 0xFFFFFFFF))\n\n_remote_debugging.BinaryReader(fn) # attempts a ~120 GB allocation\n```\n\nOn an unpatched build this drives the process to several gigabytes of RSS (and\ncan hang) from a ~100-byte file. The string table is affected the same way via\n`strings_count` (footer offset 0).\n\n## Expected behavior\n\nThe reader should reject a declared count that cannot be backed by the file's\nbytes with a `ValueError`, the same way the RLE sample count is already bounded\nin `binary_reader_replay`.\n\nThis is a sibling of gh-148252, which hardened the same reader against malformed\n`.pyb` files; the eager string/frame table allocations were not covered there.\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-152719\n* gh-153050\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/tonghuaroot","@type":"Person","name":"tonghuaroot"},"datePublished":"2026-07-01T02:14:06Z","url":"https://github.com/python/cpython/issues/152718"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:aa90449c-9d03-4fb8-5551-09f805399aa7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A57C:2454CC:43582DA:5555A55:6B022F75 |
| html-safe-nonce | 44f88fe57af31f2986f24320402b26c8b6762d47351b6e14558245404498c18c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNTdDOjI0NTRDQzo0MzU4MkRBOjU1NTVBNTU6NkIwMjJGNzUiLCJ2aXNpdG9yX2lkIjoiMjI3ODMzMzAyMzkyMzYxMzU1NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 3cebc202c0f819e3beacf5fceb0ac62f375cfb1f5eefc29f345121cbcd9cb111 |
| hovercard-subject-tag | issue:4781798413 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/152718/issue_layout |
| twitter:image | https://opengraph.githubassets.com/99c28f1370c2de4a8fcb9863bd0bbc29cb809e269b7fa070b43521574b103215/python/cpython/issues/152718 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/99c28f1370c2de4a8fcb9863bd0bbc29cb809e269b7fa070b43521574b103215/python/cpython/issues/152718 |
| og:image:alt | Bug report Bug description The binary profile reader in _remote_debugging (used by python -m profiling.sampling to replay .pyb files) reads the string-table and frame-table entry counts from the fi... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | tonghuaroot |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width