libgit2 / pygit2

Python bindings for libgit2
https://www.pygit2.org/
Other
1.59k stars 383 forks source link

pygit error: _pygit2.GitError: $hash: error inflating zlib stream [reproducer included!] #1076

Closed rralf closed 3 years ago

rralf commented 3 years ago

Hi,

This is my environment (Arch Linux, latest packages):

pygit2: 1.5.0
libgit2: 1.1
Python 3.9.4
zlib 1.2.11

Consider this reproducer:

#!/usr/bin/env python3

import pygit2

repo = pygit2.Repository('.') # Use this repo: $ git clone https://lore.kernel.org/netdev/0

commit = repo['7c260769a628415a753e77d16b56900c5df3a5c8']
tree = commit.tree
blob_hash = commit.tree['m'].hex
data = repo[blob_hash].data

I constantly receive the following error message:

Traceback (most recent call last): File "[...]./test.py", line 10, in data = repo[blob_hash].data File "/usr/lib/python3.9/site-packages/pygit2/repository.py", line 208, in getitem value = self.git_object_lookup_prefix(key) _pygit2.GitError: 7898ba1260cad632beada434f011b2c3a7a4c3f5: error inflating zlib stream

Any suggestions?

Thanks in advance!

Enselic commented 3 years ago

I can reproduce. Did you try to reproduce with pure libgit2 though? Seems to me like this is reproducible in pure C, which would make this bug unrelated to the pygit2 bindings.

rralf commented 3 years ago
#include <git2.h>
#include <stdio.h>

int main(void)
{
        git_repository *repo = NULL;
        git_tree_entry *entry = NULL;
        git_commit *commit = NULL;
        git_tree *tree = NULL;
        git_blob *blob = NULL;
        const git_error *e;
        git_oid oid;
        int error;

        git_libgit2_init();

        error = git_repository_open(&repo, ".");
        if (error)
                goto err;

        error = git_oid_fromstr(&oid, "7c260769a628415a753e77d16b56900c5df3a5c8");
        if (error)
                goto err;

        error = git_commit_lookup(&commit, repo, &oid);
        if (error)
                goto err;

        error = git_commit_tree(&tree, commit);
        if (error)
                goto err;

        error = git_tree_entry_bypath(&entry, tree, "m");
        if (error)
                goto err;

        if (git_tree_entry_type(entry) != GIT_OBJECT_BLOB)
                goto err;

        error = git_blob_lookup(&blob, repo, git_tree_entry_id(entry));
        if (error)
                goto err;

        git_tree_entry_free(entry);
        puts(git_blob_rawcontent(blob));

        return 0;
err:
        e = git_error_last();
        printf("Error %d/%d: %s\n", error, e->klass, e->message);
        return error;
}
$ gcc -ggdb -O0 test.c -o test -lgit2 -Wall -Wextra && ./test
Error -1/5: error inflating zlib stream

Narf. I'll report it over there. I guess we can close this for the moment. Thanks.

rralf commented 3 years ago

Check out the bug report on libgit2: https://github.com/libgit2/libgit2/issues/5899