Skip to content

Conversation

@dhruvang21
Copy link

@dhruvang21 dhruvang21 requested a review from a team as a code owner November 11, 2025 13:39
Copy link
Member

@swissspidy swissspidy left a comment

Choose a reason for hiding this comment

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

Thanks a lot for your PR!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds validation for downloaded files before they are cached to prevent corrupt or invalid files from being stored in the cache, addressing issue #6148. The validation includes basic file existence and size checks, as well as ZIP file integrity verification using the ZipArchive class.

Key Changes

  • Added a new validate_downloaded_file() method that performs file validation before caching
  • Integrated validation into the filter_http_response() method to check files before they're imported into the cache
  • Added ZIP file-specific validation to ensure archive integrity

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link

codecov bot commented Nov 11, 2025

Codecov Report

❌ Patch coverage is 55.55556% with 12 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
php/WP_CLI/WpHttpCacheManager.php 55.55% 12 Missing ⚠️

📢 Thoughts on this report? Let us know!

dhruvang21 and others added 2 commits November 12, 2025 11:10
Co-authored-by: Pascal Birchler <pascal.birchler@gmail.com>
@swissspidy swissspidy requested a review from a team November 12, 2025 11:10
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +127 to +139
if ( ( 'zip' === $ext || 'application/zip' === $mime ) && class_exists( '\ZipArchive' ) ) {
$zip = new \ZipArchive();
$result = $zip->open( $file );
if ( true !== $result ) {
return false;
}
// Optional deeper check: ensure we can read file list.
if ( 0 === $zip->numFiles ) { //phpcs:ignore
$zip->close();
return false;
}
$zip->close();
}
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

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

The resource leak can occur if $zip->open() succeeds but $zip->numFiles is 0. The $zip->close() is only called in the zero-files case, but not when the function returns true. This creates a resource leak where the ZipArchive remains open.

Consider closing the zip file in all code paths:

if ( ( 'zip' === $ext || 'application/zip' === $mime ) && class_exists( '\ZipArchive' ) ) {
    $zip    = new \ZipArchive();
    $result = $zip->open( $file );
    if ( true !== $result ) {
        return false;
    }
    // Optional deeper check: ensure we can read file list.
    $is_valid = $zip->numFiles > 0;
    $zip->close();
    if ( ! $is_valid ) {
        return false;
    }
}

Copilot uses AI. Check for mistakes.
dhruvang21 and others added 4 commits December 3, 2025 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cache file validation in cache manager

2 participants