René's URL Explorer Experiment


Title: Assert and incorrect error message when loading source file containing invalid UTF-8 · Issue #96268 · python/cpython · GitHub

Open Graph Title: Assert and incorrect error message when loading source file containing invalid UTF-8 · Issue #96268 · python/cpython

X Title: Assert and incorrect error message when loading source file containing invalid UTF-8 · Issue #96268 · python/cpython

Description: Bug report When loading a file containing invalid UTF-8, without a source encoding marker, an assert is emitted. If assert is removed, the error message is close, but not quite correct and has incorrect position information. To reproduce...

Open Graph Description: Bug report When loading a file containing invalid UTF-8, without a source encoding marker, an assert is emitted. If assert is removed, the error message is close, but not quite correct and has inco...

X Description: Bug report When loading a file containing invalid UTF-8, without a source encoding marker, an assert is emitted. If assert is removed, the error message is close, but not quite correct and has inco...

Opengraph URL: https://github.com/python/cpython/issues/96268

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Assert and incorrect error message when loading source file containing invalid UTF-8","articleBody":"# Bug report\r\n\r\nWhen loading a file containing invalid UTF-8, without a source encoding marker, an assert is emitted. If assert is removed, the error message is close, but not quite correct and has incorrect position information.\r\n\r\nTo reproduce, create a file with an invalid UTF-8 start byte followed by a valid continuation byte, for example, the sort of contrived and grammatically incorrect:\r\n\r\n```\r\nopen(\"x.py\", \"w\", encoding=\"latin-1\").write(\"\\n\\n\\n'HOLÀ¡'\\n\")\r\n```\r\n\r\nresults in:\r\n\r\n```\r\n$ ./python x.py \r\npython: Parser/pegen_errors.c:335: _PyPegen_raise_error_known_location: Assertion `p-\u003etok-\u003efp == NULL || p-\u003etok-\u003efp == stdin || p-\u003etok-\u003edone == E_EOF' failed.\r\n[1]    16448 IOT instruction  ./python x.py\r\n```\r\n\r\n\u003cdetails\u003e\u003csummary\u003eBacktrace\u003c/summary\u003e\r\n\r\n```\r\n#0  __pthread_kill_implementation (threadid=\u003coptimized out\u003e, signo=signo@entry=6, no_tid=no_tid@entry=0)\r\n    at ./nptl/pthread_kill.c:44\r\n#1  0x00007ffff7d6389f in __pthread_kill_internal (signo=6, threadid=\u003coptimized out\u003e)\r\n    at ./nptl/pthread_kill.c:78\r\n#2  0x00007ffff7d17a52 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26\r\n#3  0x00007ffff7d02469 in __GI_abort () at ./stdlib/abort.c:79\r\n#4  0x00007ffff7d02395 in __assert_fail_base (fmt=0x7ffff7e8fc30 \"%s%s%s:%u: %s%sAssertion `%s' failed.\\n%n\",\r\n    assertion=0x5555558a5a10 \"p-\u003etok-\u003efp == NULL || p-\u003etok-\u003efp == stdin || p-\u003etok-\u003edone == E_EOF\",\r\n    file=0x5555558a5898 \"Parser/pegen_errors.c\", line=335, function=\u003coptimized out\u003e) at ./assert/assert.c:92\r\n#5  0x00007ffff7d10b02 in __GI___assert_fail (\r\n    assertion=assertion@entry=0x5555558a5a10 \"p-\u003etok-\u003efp == NULL || p-\u003etok-\u003efp == stdin || p-\u003etok-\u003edone == E_EOF\", file=file@entry=0x5555558a5898 \"Parser/pegen_errors.c\", line=line@entry=335,\r\n    function=function@entry=0x5555558a5c40 \u003c__PRETTY_FUNCTION__.1\u003e \"_PyPegen_raise_error_known_location\")\r\n    at ./assert/assert.c:101\r\n#6  0x000055555564c7be in _PyPegen_raise_error_known_location (p=0x7ffff7a8c880,\r\n    errtype=0x555555a1cb20 \u003c_PyExc_SyntaxError\u003e, lineno=4, col_offset=8, end_lineno=4, end_col_offset=8,\r\n    errmsg=0x5555558a5946 \"(%s) %U\", va=0x7fffffffd058) at Parser/pegen_errors.c:335\r\n#7  0x000055555564cc08 in _PyPegen_raise_error (p=p@entry=0x7ffff7a8c880, errtype=\u003coptimized out\u003e,\r\n    errmsg=errmsg@entry=0x5555558a5946 \"(%s) %U\") at Parser/pegen_errors.c:235\r\n#8  0x000055555564cedb in _Pypegen_raise_decode_error (p=p@entry=0x7ffff7a8c880) at Parser/pegen_errors.c:133\r\n#9  0x000055555564eb1f in _PyPegen_concatenate_strings (p=p@entry=0x7ffff7a8c880,\r\n    strings=strings@entry=0x555555c13290) at Parser/action_helpers.c:957\r\n#10 0x00005555556598cf in strings_rule (p=p@entry=0x7ffff7a8c880) at Parser/parser.c:15481\r\n#11 0x000055555566362f in atom_rule (p=p@entry=0x7ffff7a8c880) at Parser/parser.c:14292\r\n#12 0x000055555567c149 in t_primary_raw (p=p@entry=0x7ffff7a8c880) at Parser/parser.c:18126\r\n#13 0x000055555567c4ac in t_primary_rule (p=p@entry=0x7ffff7a8c880) at Parser/parser.c:17916\r\n#14 0x0000555555680978 in single_subscript_attribute_target_rule (p=p@entry=0x7ffff7a8c880)\r\n    at Parser/parser.c:17805\r\n#15 0x00005555556813e4 in _tmp_12_rule (p=p@entry=0x7ffff7a8c880) at Parser/parser.c:24220\r\n#16 0x00005555556a5bb0 in assignment_rule (p=p@entry=0x7ffff7a8c880) at Parser/parser.c:2245\r\n#17 0x00005555556a9f37 in simple_stmt_rule (p=p@entry=0x7ffff7a8c880) at Parser/parser.c:1652\r\n#18 0x00005555556ab747 in simple_stmts_rule (p=p@entry=0x7ffff7a8c880) at Parser/parser.c:1547\r\n#19 0x00005555556ac6f6 in statement_rule (p=p@entry=0x7ffff7a8c880) at Parser/parser.c:1370\r\n#20 0x00005555556ac969 in _loop1_3_rule (p=p@entry=0x7ffff7a8c880) at Parser/parser.c:23651\r\n#21 0x00005555556acb51 in statements_rule (p=p@entry=0x7ffff7a8c880) at Parser/parser.c:1302\r\n#22 0x00005555556b4ea0 in file_rule (p=0x7ffff7a8c880) at Parser/parser.c:1061\r\n#23 0x00005555556b6953 in _PyPegen_parse (p=p@entry=0x7ffff7a8c880) at Parser/parser.c:38772\r\n#24 0x000055555564bfc6 in _PyPegen_run_parser (p=p@entry=0x7ffff7a8c880) at Parser/pegen.c:811\r\n#25 0x000055555564c1b2 in _PyPegen_run_parser_from_file_pointer (fp=fp@entry=0x555555be4310,\r\n    start_rule=start_rule@entry=257, filename_ob=filename_ob@entry=0x7ffff7aa9150, enc=enc@entry=0x0,\r\n    ps1=ps1@entry=0x0, ps2=ps2@entry=0x0, flags=0x7fffffffd8a8, errcode=0x0, arena=0x7ffff7a939a0)\r\n    at Parser/pegen.c:884\r\n#26 0x00005555556b8c2f in _PyParser_ASTFromFile (fp=fp@entry=0x555555be4310,\r\n    filename_ob=filename_ob@entry=0x7ffff7aa9150, enc=enc@entry=0x0, mode=mode@entry=257, ps1=ps1@entry=0x0,\r\n    ps2=ps2@entry=0x0, flags=0x7fffffffd8a8, errcode=0x0, arena=0x7ffff7a939a0) at Parser/peg_api.c:26\r\n#27 0x0000555555813ca1 in pyrun_file (fp=fp@entry=0x555555be4310, filename=filename@entry=0x7ffff7aa9150,\r\n    start=start@entry=257, globals=globals@entry=0x7ffff7a45010, locals=locals@entry=0x7ffff7a45010,\r\n    closeit=closeit@entry=1, flags=0x7fffffffd8a8) at Python/pythonrun.c:1620\r\n#28 0x0000555555816941 in _PyRun_SimpleFileObject (fp=fp@entry=0x555555be4310,\r\n    filename=filename@entry=0x7ffff7aa9150, closeit=closeit@entry=1, flags=flags@entry=0x7fffffffd8a8)\r\n    at Python/pythonrun.c:439\r\n#29 0x0000555555816af5 in _PyRun_AnyFileObject (fp=fp@entry=0x555555be4310,\r\n    filename=filename@entry=0x7ffff7aa9150, closeit=closeit@entry=1, flags=flags@entry=0x7fffffffd8a8)\r\n    at Python/pythonrun.c:78\r\n#30 0x00005555558332bf in pymain_run_file_obj (program_name=program_name@entry=0x7ffff7aa91c0,\r\n    filename=filename@entry=0x7ffff7aa9150, skip_source_first_line=0) at Modules/main.c:360\r\n#31 0x00005555558333c1 in pymain_run_file (config=config@entry=0x555555b29490 \u003c_PyRuntime+69264\u003e)\r\n    at Modules/main.c:379\r\n#32 0x0000555555833a99 in pymain_run_python (exitcode=exitcode@entry=0x7fffffffd9fc) at Modules/main.c:610\r\n#33 0x0000555555833cea in Py_RunMain () at Modules/main.c:689\r\n#34 0x0000555555833d3f in pymain_main (args=args@entry=0x7fffffffda40) at Modules/main.c:719\r\n#35 0x0000555555833dc4 in Py_BytesMain (argc=\u003coptimized out\u003e, argv=\u003coptimized out\u003e) at Modules/main.c:743\r\n#36 0x000055555564a742 in main (argc=\u003coptimized out\u003e, argv=\u003coptimized out\u003e) at ./Programs/python.c:15\r\n\r\n```\r\n\u003c/details\u003e\r\n\r\nIn the above assert, `p-\u003etok-\u003edone` is `E_OK`.\r\n\r\nBypassing the assert, you get an incorrect position (it should be 7, not 3):\r\n\r\n```\r\n  File \"x.py\", line 4\r\n    'HOL��'\r\n           ^\r\nSyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xc0 in position 3: invalid start byte\r\n```\r\n\r\n# Your environment\r\n\r\nLinux, Python 3.11\r\n\r\nThis bug was found because the coverage-related test added in #94856 failed on some buildbots.  For them to fail, they need to both (1) build with `--with-pydebug` and (2) have coredumps enabled in the OS.  That test should probably be fixed so it fails consistently across all buildbots, even the ones that aren't set up that way.","author":{"url":"https://github.com/mdboom","@type":"Person","name":"mdboom"},"datePublished":"2022-08-25T13:55:51.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/96268/cpython/issues/96268"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:07f7648d-2014-14b9-5c03-65c298c72a0a
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9E6A:23762:A7E458:DFD9FB:696991E9
html-safe-nonce90854b04a4bf63dd6d3b07b9f30ed81b72c1577e80c2617b768ddddfdfebd452
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RTZBOjIzNzYyOkE3RTQ1ODpERkQ5RkI6Njk2OTkxRTkiLCJ2aXNpdG9yX2lkIjoiNTM2NjU3MzcxOTg2MzUyOTk2MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac58e476fa1ce52c58f7f55fa75e133fdfff923936b18196d4e3f085c3631e4b03
hovercard-subject-tagissue:1350944341
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/96268/issue_layout
twitter:imagehttps://opengraph.githubassets.com/5dd73080346fb9cfc19a6eb78620b7f838f2f22b78dba289cbf193c4a2136f8e/python/cpython/issues/96268
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/5dd73080346fb9cfc19a6eb78620b7f838f2f22b78dba289cbf193c4a2136f8e/python/cpython/issues/96268
og:image:altBug report When loading a file containing invalid UTF-8, without a source encoding marker, an assert is emitted. If assert is removed, the error message is close, but not quite correct and has inco...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamemdboom
hostnamegithub.com
expected-hostnamegithub.com
None3542e147982176a7ebaa23dfb559c8af16f721c03ec560c68c56b64a0f35e751
turbo-cache-controlno-preview
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
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releaseaf80af7cc9e3de9c336f18b208a600950a3c187c
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/issues/96268#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F96268
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%2Fissues%2F96268
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%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/96268
Reloadhttps://github.com/python/cpython/issues/96268
Reloadhttps://github.com/python/cpython/issues/96268
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/issues/96268
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/issues/96268
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
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/96268
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/96268
Assert and incorrect error message when loading source file containing invalid UTF-8https://github.com/python/cpython/issues/96268#top
https://github.com/mdboom
3.10only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.10%22
3.11only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.11%22
3.7 (EOL)end of lifehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.7%20(EOL)%22
3.8 (EOL)end of lifehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.8%20(EOL)%22
3.9 (EOL)end of lifehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.9%20(EOL)%22
topic-unicodehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-unicode%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/mdboom
https://github.com/mdboom
mdboomhttps://github.com/mdboom
on Aug 25, 2022https://github.com/python/cpython/issues/96268#issue-1350944341
#94856https://github.com/python/cpython/pull/94856
mdboomhttps://github.com/mdboom
3.10only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.10%22
3.11only security fixeshttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.11%22
3.7 (EOL)end of lifehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.7%20(EOL)%22
3.8 (EOL)end of lifehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.8%20(EOL)%22
3.9 (EOL)end of lifehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%223.9%20(EOL)%22
topic-unicodehttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-unicode%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
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.