René's URL Explorer Experiment


Title: gh-95778: Add pre-check for int-to-str conversion by mdickinson · Pull Request #96537 · python/cpython · GitHub

Open Graph Title: gh-95778: Add pre-check for int-to-str conversion by mdickinson · Pull Request #96537 · python/cpython

X Title: gh-95778: Add pre-check for int-to-str conversion by mdickinson · Pull Request #96537 · python/cpython

Description: On current main, converting a large enough int to a decimal string raises ValueError as expected. However, the raise comes after the quadratic-time base-conversion algorithm has run to completion. For effective DOS prevention, we need some kind of check before entering the quadratic-time loop. This PR gives a proof-of-concept quick fix: essentially we catch most values that exceed the threshold up front. Those that slip through will still be on the small side, and will get caught by the existing check. For the record, here's the justification for the current check. The C code check is: max_str_digits / (3 * PyLong_SHIFT) <= (size_a - 11) / 10 In math-speak, writing $M$ for max_str_digits, $L$ for PyLong_SHIFT and $s$ for size_a, that check is: $$\left\lfloor\frac{M}{3L}\right\rfloor \le \left\lfloor\frac{s - 11}{10}\right\rfloor$$ From this it follows that $$\frac{M}{3L} < \frac{s-1}{10}$$ hence that $$\frac{L(s-1)}{M} > \frac{10}{3} > \log_2(10).$$ So $$2^{L(s-1)} > 10^M.$$ But our input integer $a$ satisfies $|a| \ge 2^{L(s-1)}$, so $|a|$ is larger than $10^M$. This shows that we don't accidentally capture anything below the intended limit in the check. I don't think this is ready to merge as-is - there are some details to figure out, and I'll add line-by-line comments for those. Issue: gh-95778

Open Graph Description: On current main, converting a large enough int to a decimal string raises ValueError as expected. However, the raise comes after the quadratic-time base-conversion algorithm has run to completion. ...

X Description: On current main, converting a large enough int to a decimal string raises ValueError as expected. However, the raise comes after the quadratic-time base-conversion algorithm has run to completion. ...

Opengraph URL: https://github.com/python/cpython/pull/96537

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:a5bf93c6-306f-21a0-ebf2-1d6a1a6d5df9
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idB9A6:140A20:63767D:85AAB1:6969B4DE
html-safe-nonce868d688bafa97fccd1f2ab6d6f3bf72c40ada0096f3cba6201e48444374e4586
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOUE2OjE0MEEyMDo2Mzc2N0Q6ODVBQUIxOjY5NjlCNERFIiwidmlzaXRvcl9pZCI6Ijg2MjMxOTA2Mjg2MjA2NzgzNjYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac8e3283af1b1cbfa7ef99723c341cd45a4aba69f4cc26d15ec8c6625d6ec8b34a
hovercard-subject-tagpull_request:1045512590
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python/cpython/pull/96537/files
twitter:imagehttps://avatars.githubusercontent.com/u/662003?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/662003?s=400&v=4
og:image:altOn current main, converting a large enough int to a decimal string raises ValueError as expected. However, the raise comes after the quadratic-time base-conversion algorithm has run to completion. ...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Noneb23b8fcc855cd29bb04d6c94aafa62d336bf44eefa8229444eecc968cad03aee
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release0672399d88424758731ec07fe24509e23bb17fb5
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/96537/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F96537%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F96537%2Ffiles
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/pull/96537/files
Reloadhttps://github.com/python/cpython/pull/96537/files
Reloadhttps://github.com/python/cpython/pull/96537/files
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/pull/96537/files
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 33.9k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 71.1k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.1k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects 31 https://github.com/python/cpython/projects
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/python/cpython/security
Please reload this pagehttps://github.com/python/cpython/pull/96537/files
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
gpsheadhttps://github.com/gpshead
python:mainhttps://github.com/python/cpython/tree/main
mdickinson:fix/int-to-str-doshttps://github.com/mdickinson/cpython/tree/fix/int-to-str-dos
Conversation 17 https://github.com/python/cpython/pull/96537
Commits 14 https://github.com/python/cpython/pull/96537/commits
Checks 0 https://github.com/python/cpython/pull/96537/checks
Files changed https://github.com/python/cpython/pull/96537/files
Please reload this pagehttps://github.com/python/cpython/pull/96537/files
gh-95778: Add pre-check for int-to-str conversion https://github.com/python/cpython/pull/96537/files#top
Show all changes 14 commits https://github.com/python/cpython/pull/96537/files
2fbc9ce Add pre-check for int-to-str conversion mdickinson Sep 3, 2022 https://github.com/python/cpython/pull/96537/commits/2fbc9cea2eece673ad3288518bd1129008182742
d16db91 Avoid potential undefined behaviour from overflow mdickinson Sep 3, 2022 https://github.com/python/cpython/pull/96537/commits/d16db91dcccc7b0e5fb8b7c0f339190132b7c042
66a07ac Reworked, even cruder bound, that avoids potential issues with intege… mdickinson Sep 3, 2022 https://github.com/python/cpython/pull/96537/commits/66a07ac000546ea6e5ead8498ccfeb32b6b76f13
6eadbda Rename the error message constants. gpshead Sep 4, 2022 https://github.com/python/cpython/pull/96537/commits/6eadbdaef34212b47b729bf77d59ad83bb387611
195686c Add a DoS prevention success timed regression test. gpshead Sep 4, 2022 https://github.com/python/cpython/pull/96537/commits/195686ca965a5097e4b22d4682e6938ad6baa7c1
87bd23d Improve the test to check close to the limit. gpshead Sep 4, 2022 https://github.com/python/cpython/pull/96537/commits/87bd23d3df3aca81b88a5f245e70fded7055ab92
de9ed4d Use fewer digits in the test to speed it up on slow hosts. gpshead Sep 4, 2022 https://github.com/python/cpython/pull/96537/commits/de9ed4d81b40f2080110a8ca13994e29caacec9f
dbd8da9 Misc: Fix a typo in the header comment. gpshead Sep 4, 2022 https://github.com/python/cpython/pull/96537/commits/dbd8da99c2d77dac9bf8379035fc39c9761636d5
c49a737 Change timers if process_time() returns 0. #wasm gpshead Sep 4, 2022 https://github.com/python/cpython/pull/96537/commits/c49a737eaa4a780b2bf604d06a52ef7eb0258758
35c5ea7 Merge branch 'main' into fix/int-to-str-dos gpshead Sep 4, 2022 https://github.com/python/cpython/pull/96537/commits/35c5ea76279a99a8661a9f5acc5b8017a69048bd
730915d Update comment to suggest reading the PR for detail gpshead Sep 4, 2022 https://github.com/python/cpython/pull/96537/commits/730915df6b236d1937466c724cc53c79009ef532
56f08c2 Minor comment typo fix (restart CI). gpshead Sep 4, 2022 https://github.com/python/cpython/pull/96537/commits/56f08c28c33bfa035ccb1b76599b262b6150cc0e
4dae3e0 cleanup the test. gpshead Sep 4, 2022 https://github.com/python/cpython/pull/96537/commits/4dae3e0494bc45b386b243f53b8d19bfb9e29d47
adb1784 Add Mark's name to the NEWS entry. gpshead Sep 4, 2022 https://github.com/python/cpython/pull/96537/commits/adb17840c496a0497fff5d07688d26d60cbfe629
Clear filters https://github.com/python/cpython/pull/96537/files
Please reload this pagehttps://github.com/python/cpython/pull/96537/files
Please reload this pagehttps://github.com/python/cpython/pull/96537/files
pycore_long.h https://github.com/python/cpython/pull/96537/files#diff-0817b8ffc6c3af36ea39ebabafe70c849d6ee7cb6621d3bda857f3ed25a37511
test_int.py https://github.com/python/cpython/pull/96537/files#diff-18ccbdfd8076e3f5b7f84f250e7f312799c3db073d3c8e351f5ce4ad18d3c304
2022-08-07-16-53-38.gh-issue-95778.ch010gps.rst https://github.com/python/cpython/pull/96537/files#diff-b43b52d1cb3cc2776e975eb3e4fdf44450f93ea09002ea3ef6ce4c982c8e9ac4
longobject.c https://github.com/python/cpython/pull/96537/files#diff-1a6e70e2beeecad88840c67284ac4d54a36998029244771fcc820e801390726a
Include/internal/pycore_long.hhttps://github.com/python/cpython/pull/96537/files#diff-0817b8ffc6c3af36ea39ebabafe70c849d6ee7cb6621d3bda857f3ed25a37511
View file https://github.com/mdickinson/cpython/blob/adb17840c496a0497fff5d07688d26d60cbfe629/Include/internal/pycore_long.h
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/96537/{{ revealButtonHref }}
https://github.com/python/cpython/pull/96537/files#diff-0817b8ffc6c3af36ea39ebabafe70c849d6ee7cb6621d3bda857f3ed25a37511
https://github.com/python/cpython/pull/96537/files#diff-0817b8ffc6c3af36ea39ebabafe70c849d6ee7cb6621d3bda857f3ed25a37511
Lib/test/test_int.pyhttps://github.com/python/cpython/pull/96537/files#diff-18ccbdfd8076e3f5b7f84f250e7f312799c3db073d3c8e351f5ce4ad18d3c304
View file https://github.com/mdickinson/cpython/blob/adb17840c496a0497fff5d07688d26d60cbfe629/Lib/test/test_int.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/96537/{{ revealButtonHref }}
https://github.com/python/cpython/pull/96537/files#diff-18ccbdfd8076e3f5b7f84f250e7f312799c3db073d3c8e351f5ce4ad18d3c304
https://github.com/python/cpython/pull/96537/files#diff-18ccbdfd8076e3f5b7f84f250e7f312799c3db073d3c8e351f5ce4ad18d3c304
https://github.com/python/cpython/pull/96537/files#diff-18ccbdfd8076e3f5b7f84f250e7f312799c3db073d3c8e351f5ce4ad18d3c304
Misc/NEWS.d/next/Security/2022-08-07-16-53-38.gh-issue-95778.ch010gps.rsthttps://github.com/python/cpython/pull/96537/files#diff-b43b52d1cb3cc2776e975eb3e4fdf44450f93ea09002ea3ef6ce4c982c8e9ac4
View file https://github.com/mdickinson/cpython/blob/adb17840c496a0497fff5d07688d26d60cbfe629/Misc/NEWS.d/next/Security/2022-08-07-16-53-38.gh-issue-95778.ch010gps.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/96537/{{ revealButtonHref }}
https://github.com/python/cpython/pull/96537/files#diff-b43b52d1cb3cc2776e975eb3e4fdf44450f93ea09002ea3ef6ce4c982c8e9ac4
Objects/longobject.chttps://github.com/python/cpython/pull/96537/files#diff-1a6e70e2beeecad88840c67284ac4d54a36998029244771fcc820e801390726a
View file https://github.com/mdickinson/cpython/blob/adb17840c496a0497fff5d07688d26d60cbfe629/Objects/longobject.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/96537/{{ revealButtonHref }}
https://github.com/python/cpython/pull/96537/files#diff-1a6e70e2beeecad88840c67284ac4d54a36998029244771fcc820e801390726a
https://github.com/python/cpython/pull/96537/files#diff-1a6e70e2beeecad88840c67284ac4d54a36998029244771fcc820e801390726a
https://github.com/python/cpython/pull/96537/files#diff-1a6e70e2beeecad88840c67284ac4d54a36998029244771fcc820e801390726a
https://github.com/python/cpython/pull/96537/files#diff-1a6e70e2beeecad88840c67284ac4d54a36998029244771fcc820e801390726a
https://github.com/python/cpython/pull/96537/files#diff-1a6e70e2beeecad88840c67284ac4d54a36998029244771fcc820e801390726a
https://github.com/python/cpython/pull/96537/files#diff-1a6e70e2beeecad88840c67284ac4d54a36998029244771fcc820e801390726a
https://github.com/python/cpython/pull/96537/files#diff-1a6e70e2beeecad88840c67284ac4d54a36998029244771fcc820e801390726a
https://github.com/python/cpython/pull/96537/files#diff-1a6e70e2beeecad88840c67284ac4d54a36998029244771fcc820e801390726a
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.