Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: Fix content type check in AbstractHttpGitClient._smart_request #1192

Merged
merged 1 commit into from
Jul 5, 2023

Conversation

anlambert
Copy link
Contributor

Some git servers can send a Content-Type header containing a charset directive.

$ echo -e "0079want 034350e047bbb1892a917c51f065f2e8125a6bf7 multi_ack multi_ack_detailed ofs-delta shallow side-band-64k thin-pack\n0032want 034350e047bbb1892a917c51f065f2e8125a6bf7\n0032want 67106b8421ca9e5fe77e46766e754e29390abb89\n00000009done\n" | curl -i -X POST --data-binary @- -H "Content-Type: application/x-git-upload-pack-request" https://hacktivis.me/git/blog.git/git-upload-pack
HTTP/2 200 
server: nginx/1.23.3
date: Wed, 05 Jul 2023 10:41:01 GMT
content-type: application/x-git-upload-pack-result; charset=utf-8
expires: Fri, 01 Jan 1980 00:00:00 GMT
pragma: no-cache
cache-control: no-cache, max-age=0, must-revalidate
x-frame-options: sameorigin
x-content-type-options: nosniff
x-xss-protection: 1; mode=block
referrer-policy: no-referrer
strict-transport-security: max-age=63072000; includeSubDomains; preload
content-security-policy: default-src 'none'

Warning: Binary output can mess up your terminal. Use "--output -" to tell 
Warning: curl to output it to your terminal anyway, or consider "--output 
Warning: <FILE>" to save to a file.

Official git client can successfully clone repositories hosted on such server but dulwich
was raising a GitProtocolError as the code to check the header value was not expecting
a directive to be present in it.

$ git clone https://hacktivis.me/git/blog.git
Cloning into 'blog'...
remote: Enumerating objects: 6287, done.
remote: Total 6287 (delta 0), reused 0 (delta 0), pack-reused 6287
Receiving objects: 100% (6287/6287), 10.01 MiB | 4.63 MiB/s, done.
Resolving deltas: 100% (4279/4279), done.

$ python
Python 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from dulwich.porcelain import clone
>>> clone("https://hacktivis.me/git/blog.git")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/anlambert/dev/dulwich/dulwich/porcelain.py", line 542, in clone
    return client.clone(
           ^^^^^^^^^^^^^
  File "/home/anlambert/dev/dulwich/dulwich/client.py", line 735, in clone
    result = self.fetch(path, target, progress=progress, depth=depth)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/anlambert/dev/dulwich/dulwich/client.py", line 813, in fetch
    result = self.fetch_pack(
             ^^^^^^^^^^^^^^^^
  File "/home/anlambert/dev/dulwich/dulwich/client.py", line 2133, in fetch_pack
    resp, read = self._smart_request(
                 ^^^^^^^^^^^^^^^^^^^^
  File "/home/anlambert/dev/dulwich/dulwich/client.py", line 2011, in _smart_request
    raise GitProtocolError(
dulwich.errors.GitProtocolError: Invalid content-type from server: application/x-git-upload-pack-result; charset=utf-8

The issue was spotted by the Software Heritage git loader.

Some git servers can send a Content-Type header containing a charset
directive. Official git client can successfully clone repositories
hosted on such server but dulwich was raising a GitProtocolError as
the code to check the header value was not expecting a directive to
be present in it.
@anlambert anlambert requested a review from jelmer as a code owner July 5, 2023 11:38
@jelmer jelmer merged commit a1c3b3f into jelmer:master Jul 5, 2023
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants