Media: Normalize non-integer filesize attachment metadata in the admin#12632
Draft
mukeshpanchal27 wants to merge 2 commits into
Draft
Media: Normalize non-integer filesize attachment metadata in the admin#12632mukeshpanchal27 wants to merge 2 commits into
filesize attachment metadata in the admin#12632mukeshpanchal27 wants to merge 2 commits into
Conversation
Ensure filesize is numeric and positive before casting.
Ensure filesize is numeric and greater than zero before assignment.
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
There was a problem hiding this comment.
Pull request overview
This PR aims to harden attachment “filesize” handling by normalizing stored attachment metadata to a positive integer before it’s displayed/returned in admin/media responses.
Changes:
- In
wp_prepare_attachment_for_js(), only usesmeta['filesize']when it’s numeric and > 0, casting toint. - In
attachment_submitbox_metadata(), applies the same numeric-and-positive check and casts tointbefore formatting.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/wp-includes/media.php | Normalizes filesize attachment metadata in JS-prepared attachment payloads. |
| src/wp-admin/includes/media.php | Normalizes filesize attachment metadata shown in the attachment submitbox UI. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+4719
to
4723
| if ( isset( $meta['filesize'] ) && is_numeric( $meta['filesize'] ) && $meta['filesize'] > 0 ) { | ||
| $bytes = (int) $meta['filesize']; | ||
| } elseif ( file_exists( $attached_file ) ) { | ||
| $bytes = wp_filesize( $attached_file ); | ||
| } else { |
Comment on lines
+3428
to
3432
| if ( isset( $meta['filesize'] ) && is_numeric( $meta['filesize'] ) && $meta['filesize'] > 0 ) { | ||
| $file_size = (int) $meta['filesize']; | ||
| } elseif ( file_exists( $file ) ) { | ||
| $file_size = wp_filesize( $file ); | ||
| } |
Comment on lines
+4719
to
+4720
| if ( isset( $meta['filesize'] ) && is_numeric( $meta['filesize'] ) && $meta['filesize'] > 0 ) { | ||
| $bytes = (int) $meta['filesize']; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Trac ticket: https://core.trac.wordpress.org/ticket/65686
Use of AI Tools
AI assistance: Yes
Tool(s): Claude
Model(s): Opus 4.8
Used for: For drafting issue/PR details only.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.