Skip to content

Conversation

@muhammadolammi
Copy link
Contributor

@muhammadolammi muhammadolammi commented Jan 3, 2026

Description

This fixes the bug in the ExtractZip function; it currently creates all subfolders of the zip inside cwd when using "filename". By using filepath, we make sure it's produced in /tm,p, which other functions calling ExtractZip (like the ProcessContent) expect and depend on

Notes for Reviewers
This PR depends on "fix syntax error in registry/model.go #884" Please merge #884 first.

Signed commits

  • Yes, I signed my commits.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @muhammadolammi, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug in the ExtractZip utility, ensuring that extracted files and directories are correctly placed in the designated target path, typically a temporary directory. This fix is essential for the proper functioning of other components, such as ProcessContent, which rely on this utility to process content from zip archives without scattering files across the current working directory. Additionally, minor formatting adjustments were made in registry/model.go for improved readability.

Highlights

  • Bug Fix in Zip Extraction: The ExtractZip utility function now correctly extracts zip archive contents to the specified target directory (path) instead of inadvertently creating subfolders in the current working directory. This resolves an issue where dependent functions expected files in a specific temporary location.
  • Improved Directory Handling: The logic for creating directories during zip extraction has been enhanced by switching from os.Mkdir to os.MkdirAll, ensuring that all necessary parent directories are created automatically if they do not already exist.
  • Refactored File Operations: The internal handling of file opening and copying within the ExtractZip function has been refactored for better error management and resource cleanup. This includes moving defer statements for file descriptors inside the loop and adding a check to skip macOS resource fork files (those prefixed with ._).
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request fixes a bug in the ExtractZip function to correctly handle file paths during extraction, preventing files from being created in the current working directory. The changes also include significant improvements to resource management by fixing a file descriptor leak and using a more efficient method for copying file data. Additionally, a syntax and logic error in a loop within registry/model.go is corrected. My review identifies a critical security vulnerability (Zip Slip) in the updated ExtractZip function and provides a suggestion to mitigate it.

…rent /tmp sub folder instead of cwd

Signed-off-by: Muhammad Akewukanwo <[email protected]>
Signed-off-by: Muhammad Akewukanwo <[email protected]>
Signed-off-by: Muhammad Akewukanwo <[email protected]>
Signed-off-by: Muhammad Akewukanwo <[email protected]>
Signed-off-by: Muhammad Akewukanwo <[email protected]>
Signed-off-by: Muhammad Akewukanwo <[email protected]>
@leecalcote
Copy link
Member

@parthivsaikia, perhaps, you might offer review or @lekaf974 might have a comment or two.


for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tmpDir, _ := os.MkdirTemp("", "extract-test-*")
Copy link
Member

Choose a reason for hiding this comment

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

I think it will be better if we don't ignore these errors.

Comment on lines +62 to +64
if (err != nil) != tt.wantErr {
t.Errorf("ExtractZip() error = %v, wantErr %v", err, tt.wantErr)
}
Copy link
Member

Choose a reason for hiding this comment

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

The specific error message "zipslip: illegal file path" defined in the struct is not checked here. Please consider checking it too.

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.

3 participants