• Kirill Smelkov's avatar
    *: Fix memory corruptions caused by improper git2go usage · 7b24f69c
    Kirill Smelkov authored
    Alain reports that lab.nexedi.com backup restoration sometimes fails with error like
    
        ...
        # file gitlab/misc -> .../srv/backup/backup-gitlab.git/gitlab-backup.Pj0fpp/gitlab_backup/db/database.pgdump/7630.dat/7630.dat.ry main.cmd_restore: main.blob_to_file: write .../srv/backup/backup-gitlab.git/gitlab-backup.Pj0fpp/gitlab_backup/db/database.pgdump/7630.dat/7630.dat.ry: bad address
    
    which means that write system call invoked by writefile at tail of blob_to_file returned EFAULT.
    
    The blob_to_file function is organized approximately as this:
    
        blob_to_file(blob_sha1, path) {
            blob = ReadObject(blob_sha1, git.ObjectBlob)
            blob_content = blob.Data()
            writefile(path, blob_content)
        }
    
    and getting EFAULT inside writefile means that blob_content points to
    some unmapped memory.
    
    How that could be?
    
    The answer is that blob.Data(), as implemented by git2go, returns []byte
    that points to Cgo memory owned by blob object, and t...
    7b24f69c