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

[BUG] Resulting images broken during repo reset #273

Closed
webknjaz opened this issue Dec 18, 2018 · 5 comments
Closed

[BUG] Resulting images broken during repo reset #273

webknjaz opened this issue Dec 18, 2018 · 5 comments
Labels

Comments

@webknjaz
Copy link

I don't know what exactly happened but the resulting images got completely broken in ansible/ansible-lint repo.

Context:

Maybe you could figure out what was that from logs or so.

@dabutvin dabutvin added the bug label Dec 18, 2018
@dabutvin
Copy link
Contributor

Hey thanks for reporting this!

I just forked the project and reproduced the same outcome. Something strange for sure.
https://github.com/dabutvin/ansible-lint/pull/1/files

I wonder if there is a way we can detect this in the code here when it happens or if ImageMagick had any idea it was creating corrupted files.

@webknjaz
Copy link
Author

Maybe try loosely comparing images?

@dabutvin
Copy link
Contributor

dabutvin commented Jan 16, 2019

I got a chance to debug this further tonight and the result is pretty interesting. The compression of the image is fine, it is the git signature routine that is corrupting the image.

I didn't expect that!

Here is the relevant code snippet from the source

var signature = new Signature(KnownGitHubs.ImgBotLogin, KnownGitHubs.ImgBotEmail, DateTimeOffset.Now);
repo.Commit(commitMessage, signature, signature);

// We just made a normal commit, now we are going to capture all the values generated from that commit
// then rewind and make a signed commit
var commitBuffer = Commit.CreateBuffer(
    repo.Head.Tip.Author,
    repo.Head.Tip.Committer,
    repo.Head.Tip.Message,
    repo.Head.Tip.Tree,
    repo.Head.Tip.Parents,
    true,
    null);

var signedCommitData = CommitSignature.Sign(commitBuffer + "\n", parameters.PgpPrivateKeyStream, parameters.PgPPassword);

repo.Reset(ResetMode.Soft, repo.Head.Commits.Skip(1).First().Sha);
var commitToKeep = repo.ObjectDatabase.CreateCommitWithSignature(commitBuffer, signedCommitData);

repo.Refs.UpdateTarget(repo.Refs.Head, commitToKeep);
var branchAgain = Commands.Checkout(repo, KnownGitHubs.BranchName);
repo.Reset(ResetMode.Hard, commitToKeep.Sha);

It is the final repo.Reset call that is corrupting the images. The images are in good shape every step of the way leading up to that and are fine during the first commit

It's kind of a coincidence that this reset is causing the images to be corrupt.
If I remove the signing routine and the resets, then the images do not get corrupted on the local server, but still in the git database. A fresh clone of the repo corrupts the images - and they display corrupted in github.

So it is actually any reading from the git database that is corrupting the images.

@dabutvin dabutvin changed the title [BUG?] Resulting images broken [BUG] Resulting images broken during repo reset Jan 16, 2019
@dabutvin
Copy link
Contributor

opened #297 as a workaround so at least we don't get bad PRs.
I'm not finding a lot of information about files getting corrupted while writing to git

dabutvin added a commit that referenced this issue Jan 17, 2019
verify images are not corrupt after reset (fixes #273)
@dabutvin
Copy link
Contributor

@webknjaz thanks for reporting this issue here. Turns out the git compression was the culprit. And while we couldn't find a way to retain the compression without corrupting the images, we do have a safeguard now to stop ImgBot from pushing commits with corrupted images.

Please feel free to open more issues for any problems or questions you have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants