-
Notifications
You must be signed in to change notification settings - Fork 1k
Check cache file validation #6149
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
base: main
Are you sure you want to change the base?
Conversation
swissspidy
left a comment
There was a problem hiding this 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!
There was a problem hiding this 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 Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Co-authored-by: Pascal Birchler <pascal.birchler@gmail.com>
There was a problem hiding this 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.
| 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(); | ||
| } |
Copilot
AI
Dec 2, 2025
There was a problem hiding this comment.
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;
}
}Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This reverts commit 65424a8.
Description :-