René's URL Explorer Experiment


Title: Unhandled IndexError when calling .read() on a malformed config file · Issue #1887 · gitpython-developers/GitPython · GitHub

Open Graph Title: Unhandled IndexError when calling .read() on a malformed config file · Issue #1887 · gitpython-developers/GitPython

X Title: Unhandled IndexError when calling .read() on a malformed config file · Issue #1887 · gitpython-developers/GitPython

Description: Hi, I noticed the fuzzing tests that OSS-Fuzz runs on this project are broken and while I was working on fixing them I believe I came across a minor bug: The Bug An Uncaught Python exception: IndexError: string index out of range can be ...

Open Graph Description: Hi, I noticed the fuzzing tests that OSS-Fuzz runs on this project are broken and while I was working on fixing them I believe I came across a minor bug: The Bug An Uncaught Python exception: Index...

X Description: Hi, I noticed the fuzzing tests that OSS-Fuzz runs on this project are broken and while I was working on fixing them I believe I came across a minor bug: The Bug An Uncaught Python exception: Index...

Opengraph URL: https://github.com/gitpython-developers/GitPython/issues/1887

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Unhandled IndexError when calling .read() on a malformed config file","articleBody":"Hi, I noticed the fuzzing tests that OSS-Fuzz runs on this project are broken and while I was working on fixing them I believe I came across a minor bug:\r\n\r\n## The Bug\r\n\r\nAn `Uncaught Python exception:` `IndexError: string index out of range` can be triggered if when trying to call `.read()` on `GitConfigParser` if it was initialized with a malformed config file.\r\n\r\n### Current Behavior\r\n\r\nIt's easiest to demonstrate, so please consider this example:\r\n\r\n```python\r\nimport io\r\nfrom git.config import GitConfigParser\r\n\r\n\r\ndef reproduce_issue():\r\n\r\n    malformed_config_content_bytestring = b'[-]\\nk:\"v\\n\"'\r\n\r\n    problematic_config_file = io.BytesIO(malformed_config_content_bytestring)\r\n\r\n    # problematic_config_file looks now like this:\r\n    \"\"\"\r\n    [-]\r\n    k:\"v\r\n    \"\r\n    \"\"\"\r\n\r\n    # We have to name the file otherwise we'll trigger\r\n    # `AttributeError: '_io.BytesIO' object has no attribute 'name'` here:\r\n    # https://github.com/gitpython-developers/GitPython/blob/c7675d2cedcd737f20359a4a786e213510452413/git/config.py#L623\r\n    problematic_config_file.name = \"fuzzedconfig.config\"\r\n\r\n    # This is fine\r\n    git_config = GitConfigParser(problematic_config_file)\r\n    \r\n    # The next line raised an unhandled `IndexError: string index out of range`\r\n    git_config.read()\r\n\r\n\r\nif __name__ == \"__main__\":\r\n    reproduce_issue()\r\n\r\n```\r\n\r\nAssuming that code is in `/path/to/example/config_indexerror_reproduction.py` then\r\n```sh\r\npython config_indexerror_reproduction.py\r\n```\r\nproduces something akin to:\r\n\r\n```sh\r\nTraceback (most recent call last):\r\n  File \"/path/to/example/config_indexerror_reproduction.py\", line 30, in \u003cmodule\u003e\r\n    reproduce_issue()\r\n  File \"/path/to/example/config_indexerror_reproduction.py\", line 26, in reproduce_issue\r\n    git_config.read()\r\n  File \"/path/to/example/.venv/lib/python3.12/site-packages/git/config.py\", line 607, in read\r\n    self._read(file_path, file_path.name)\r\n  File \"/path/to/example/.venv/lib/python3.12/site-packages/git/config.py\", line 514, in _read\r\n    cursect.setlast(optname, optval + string_decode(line))\r\n                                      ^^^^^^^^^^^^^^^^^^^\r\n  File \"/path/to/example/.venv/lib/python3.12/site-packages/git/config.py\", line 441, in string_decode\r\n    if v[-1] == \"\\\\\":\r\n       ~^^^^\r\nIndexError: string index out of range\r\n```\r\n\r\n\u003cdetails\u003e\u003csummary\u003eMy Reproduction Environment Details\u003c/summary\u003e\r\n\r\nThe reproduction code above was tested on:\r\n\r\n```sh\r\nPython Version: 3.12.1 (main, Feb  5 2024, 16:23:00) [Clang 15.0.0 (clang-1500.1.0.2.5)]\r\nOS Information: macOS-14.4.1-x86_64-i386-64bit\r\nInstalled Packages:\r\nPackage   Version\r\n--------- -------\r\ngitdb     4.0.11\r\nGitPython 3.1.42\r\npip       24.0\r\nsmmap     5.0.1\r\n```\r\n\r\nAnd the fuzzer environment was:\r\n```\r\nPython Version: 3.8.3 (default, Mar 17 2024, 03:21:27)\r\n[Clang 15.0.0 (https://github.com/llvm/llvm-project.git bf7f8d6fa6f460bf0a16ffe\r\nOS Information: Linux-6.6.16-linuxkit-x86_64-with-glibc2.2.5\r\nInstalled Packages:\r\nPackage                   Version\r\n------------------------- -------\r\naltgraph                  0.17.4\r\natheris                   2.3.0\r\ncoverage                  6.3.2\r\nimportlib_metadata        7.0.2\r\ngitdb                     4.0.11\r\nGitPython                 3.1.42\r\npip                       24.0\r\nsmmap                     5.0.1\r\npackaging                 24.0\r\npyinstaller               5.0.1\r\nsetuptools                41.0.1\r\nsix                       1.15.0\r\nzipp                      3.18.1\r\n```\r\n\r\n\u003c/details\u003e \r\n\r\nSo, if I'm reading the source correct, it seems like the combination of some header section (`[-]` above) followed by a key/value assignment that has a value consisting of a double quoted string with a new line inside it confuses the check here which strips the `\"` on the new line:\r\nhttps://github.com/gitpython-developers/GitPython/blob/c7675d2cedcd737f20359a4a786e213510452413/git/config.py#L521-L528\r\n\r\nand passes an empty string to `string_decode` which isn't expecting that when it indexes into it's arg:\r\nhttps://github.com/gitpython-developers/GitPython/blob/c7675d2cedcd737f20359a4a786e213510452413/git/config.py#L454-L455\r\n\r\n### Expected Behavior\r\n\r\nI'd expect an explicitly raised `ParsingError` similar to how it's handled a little further up:\r\nhttps://github.com/gitpython-developers/GitPython/blob/c7675d2cedcd737f20359a4a786e213510452413/git/config.py#L514-L518\r\n\r\n","author":{"url":"https://github.com/DaveLak","@type":"Person","name":"DaveLak"},"datePublished":"2024-03-30T19:37:43.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/1887/GitPython/issues/1887"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:2c0d51d8-a172-7895-9816-28dd3e82473c
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idB546:822D:514CEE:72332E:6968CB5C
html-safe-noncee8fdd9fe56126264fbef338cfc83f505ab1f1a2ff39c1ae92fb2c3d930ed8307
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNTQ2OjgyMkQ6NTE0Q0VFOjcyMzMyRTo2OTY4Q0I1QyIsInZpc2l0b3JfaWQiOiI4MTM4NzczMzQwNDU3ODQ3NjQ0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacab12c04dd72f8dcbff3a6f19e5de748421901722f12438d895c8f5529af0c220
hovercard-subject-tagissue:2216638669
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/gitpython-developers/GitPython/1887/issue_layout
twitter:imagehttps://opengraph.githubassets.com/22e528ddde9f3cfff9a927641dffc38ae9ccf34833cbbf6998b20b72fc045926/gitpython-developers/GitPython/issues/1887
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/22e528ddde9f3cfff9a927641dffc38ae9ccf34833cbbf6998b20b72fc045926/gitpython-developers/GitPython/issues/1887
og:image:altHi, I noticed the fuzzing tests that OSS-Fuzz runs on this project are broken and while I was working on fixing them I believe I came across a minor bug: The Bug An Uncaught Python exception: Index...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameDaveLak
hostnamegithub.com
expected-hostnamegithub.com
Noneaf2d7af0cc84117fa10bf36808605ef68a335c9d8a804b9cdac55f8d77230b00
turbo-cache-controlno-preview
go-importgithub.com/gitpython-developers/GitPython git https://github.com/gitpython-developers/GitPython.git
octolytics-dimension-user_id503709
octolytics-dimension-user_logingitpython-developers
octolytics-dimension-repository_id1126087
octolytics-dimension-repository_nwogitpython-developers/GitPython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id1126087
octolytics-dimension-repository_network_root_nwogitpython-developers/GitPython
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
releasecc844ab6ee0198cc2e2c142dcb8a5c2a61d48743
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/gitpython-developers/GitPython/issues/1887#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgitpython-developers%2FGitPython%2Fissues%2F1887
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%2Fgitpython-developers%2FGitPython%2Fissues%2F1887
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=gitpython-developers%2FGitPython
Reloadhttps://github.com/gitpython-developers/GitPython/issues/1887
Reloadhttps://github.com/gitpython-developers/GitPython/issues/1887
Reloadhttps://github.com/gitpython-developers/GitPython/issues/1887
gitpython-developers https://github.com/gitpython-developers
GitPythonhttps://github.com/gitpython-developers/GitPython
Please reload this pagehttps://github.com/gitpython-developers/GitPython/issues/1887
Notifications https://github.com/login?return_to=%2Fgitpython-developers%2FGitPython
Fork 964 https://github.com/login?return_to=%2Fgitpython-developers%2FGitPython
Star 5k https://github.com/login?return_to=%2Fgitpython-developers%2FGitPython
Code https://github.com/gitpython-developers/GitPython
Issues 169 https://github.com/gitpython-developers/GitPython/issues
Pull requests 8 https://github.com/gitpython-developers/GitPython/pulls
Discussions https://github.com/gitpython-developers/GitPython/discussions
Actions https://github.com/gitpython-developers/GitPython/actions
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/gitpython-developers/GitPython/security
Please reload this pagehttps://github.com/gitpython-developers/GitPython/issues/1887
Insights https://github.com/gitpython-developers/GitPython/pulse
Code https://github.com/gitpython-developers/GitPython
Issues https://github.com/gitpython-developers/GitPython/issues
Pull requests https://github.com/gitpython-developers/GitPython/pulls
Discussions https://github.com/gitpython-developers/GitPython/discussions
Actions https://github.com/gitpython-developers/GitPython/actions
Security https://github.com/gitpython-developers/GitPython/security
Insights https://github.com/gitpython-developers/GitPython/pulse
New issuehttps://github.com/login?return_to=https://github.com/gitpython-developers/GitPython/issues/1887
New issuehttps://github.com/login?return_to=https://github.com/gitpython-developers/GitPython/issues/1887
#1908https://github.com/gitpython-developers/GitPython/pull/1908
Unhandled IndexError when calling .read() on a malformed config filehttps://github.com/gitpython-developers/GitPython/issues/1887#top
#1908https://github.com/gitpython-developers/GitPython/pull/1908
acknowledgedhttps://github.com/gitpython-developers/GitPython/issues?q=state%3Aopen%20label%3A%22acknowledged%22
help wantedhttps://github.com/gitpython-developers/GitPython/issues?q=state%3Aopen%20label%3A%22help%20wanted%22
https://github.com/DaveLak
https://github.com/DaveLak
DaveLakhttps://github.com/DaveLak
on Mar 30, 2024https://github.com/gitpython-developers/GitPython/issues/1887#issue-2216638669
GitPython/git/config.pyhttps://github.com/gitpython-developers/GitPython/blob/c7675d2cedcd737f20359a4a786e213510452413/git/config.py#L521-L528
c7675d2https://github.com/gitpython-developers/GitPython/commit/c7675d2cedcd737f20359a4a786e213510452413
GitPython/git/config.pyhttps://github.com/gitpython-developers/GitPython/blob/c7675d2cedcd737f20359a4a786e213510452413/git/config.py#L454-L455
c7675d2https://github.com/gitpython-developers/GitPython/commit/c7675d2cedcd737f20359a4a786e213510452413
GitPython/git/config.pyhttps://github.com/gitpython-developers/GitPython/blob/c7675d2cedcd737f20359a4a786e213510452413/git/config.py#L514-L518
c7675d2https://github.com/gitpython-developers/GitPython/commit/c7675d2cedcd737f20359a4a786e213510452413
acknowledgedhttps://github.com/gitpython-developers/GitPython/issues?q=state%3Aopen%20label%3A%22acknowledged%22
help wantedhttps://github.com/gitpython-developers/GitPython/issues?q=state%3Aopen%20label%3A%22help%20wanted%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.