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

fix(index): close file before sign #1221

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,11 @@ func (idx *Index) WriteArchiveIndex(ctx context.Context, destinationFile string)
if err != nil {
return fmt.Errorf("failed to create archive file: %w", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't comment on lines that weren't changed, so I'm commenting here.
This function WriteArchiveIndex takes a destinationFile , writes to that destinationFile and then signs the idx.IndexFile. So if they're not the same thing, then destinationFile won't actually get signed.

There is only one caller of WriteArchiveIndex (GenerateIndex). So it feels like to me we should change WriteArchiveIndex to not take a destinationFile but rather just operate on idx.IndexFile rather than pretending it can do something else.

I admit I could be missing something here.

defer outFile.Close()

if _, err = io.Copy(outFile, archive); err != nil {
return fmt.Errorf("failed to write contents to archive file: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its not a super big deal, but you would leak a file descriptor here, wouldn't you?
before returning you shouldn't you outfile.Close().

And "saying" that out loud, it looks like we must also be leaking archive file descriptor, aren't we? should we defer archive.Close() above? or does that not need a close for some reason?

Copy link
Contributor

@smoser smoser May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scratch that. it is just a io.Reader, which doens't have Close. So we do not need to close archive.

}
outFile.Close()

if idx.SigningKey != "" {
log.Infof("signing apk index at %s", idx.IndexFile)
Expand Down
Loading