Title: Don't pre-allocate the Type1 /Subrs array from the declared count by vsaraikin · Pull Request #32062 · matplotlib/matplotlib · GitHub
Open Graph Title: Don't pre-allocate the Type1 /Subrs array from the declared count by vsaraikin · Pull Request #32062 · matplotlib/matplotlib
X Title: Don't pre-allocate the Type1 /Subrs array from the declared count by vsaraikin · Pull Request #32062 · matplotlib/matplotlib
Description: Fixes #31962. When parsing a Type1 font, _parse_subrs read the declared /Subrs count and immediately did array = [None] * count, before reading the body. The count comes straight from the font file, so a malformed font can declare a huge count in a handful of bytes and force a large allocation before anything is validated. _parse_charstrings already avoids this by accumulating into a dict, so this just brings _parse_subrs in line. The change accumulates the parsed entries into a dict and only allocates the count-sized result list once the body has actually been read. The regression test builds a tiny font that declares /Subrs 5000000 array with an empty body. On master that allocates ~40 MB ([None] * 5000000) before the parse fails; with the change the parse still fails the same way but peak allocation stays small. The test uses tracemalloc and asserts the peak stays under 5 MB.
Open Graph Description: Fixes #31962. When parsing a Type1 font, _parse_subrs read the declared /Subrs count and immediately did array = [None] * count, before reading the body. The count comes straight from the font file...
X Description: Fixes #31962. When parsing a Type1 font, _parse_subrs read the declared /Subrs count and immediately did array = [None] * count, before reading the body. The count comes straight from the font file...
Opengraph URL: https://github.com/matplotlib/matplotlib/pull/32062
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:05a3f635-7b83-89fe-5e5e-d09a9a25ae12 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 9D14:2AB3E6:D22E49:11FECCF:6A63BB19 |
| html-safe-nonce | 87d6f36d80ea021eb92d1c837059c9c90952673b2fdfcd73e4fbf3aa239880a2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RDE0OjJBQjNFNjpEMjJFNDk6MTFGRUNDRjo2QTYzQkIxOSIsInZpc2l0b3JfaWQiOiI3NzE3MjQxMjExMTEyODk3MzA1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | dee290f2ddede2f8151f13a024ca52d89412de83fa1bad209940a5bf2b98f8c9 |
| hovercard-subject-tag | pull_request:4081744465 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/matplotlib/matplotlib/pull/32062/files |
| twitter:image | https://avatars.githubusercontent.com/u/43279475?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/43279475?s=400&v=4 |
| og:image:alt | Fixes #31962. When parsing a Type1 font, _parse_subrs read the declared /Subrs count and immediately did array = [None] * count, before reading the body. The count comes straight from the font file... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4c1c4f1792dfc705b5a5073fed6c61988f59766cec1277f24f55d4b876f9881c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | fefaad6f0be5c33f57f42bb65ed668f74c872364 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width