Skip to content

Media: Normalize non-integer filesize attachment metadata in the admin#12632

Draft
mukeshpanchal27 wants to merge 2 commits into
WordPress:trunkfrom
mukeshpanchal27:fix/65686
Draft

Media: Normalize non-integer filesize attachment metadata in the admin#12632
mukeshpanchal27 wants to merge 2 commits into
WordPress:trunkfrom
mukeshpanchal27:fix/65686

Conversation

@mukeshpanchal27

@mukeshpanchal27 mukeshpanchal27 commented Jul 22, 2026

Copy link
Copy Markdown
Member

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.

Ensure filesize is numeric and positive before casting.
Ensure filesize is numeric and greater than zero before assignment.
Copilot AI review requested due to automatic review settings July 22, 2026 04:11
@mukeshpanchal27 mukeshpanchal27 self-assigned this Jul 22, 2026
@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copilot AI left a comment

Copy link
Copy Markdown

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 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 uses meta['filesize'] when it’s numeric and > 0, casting to int.
  • In attachment_submitbox_metadata(), applies the same numeric-and-positive check and casts to int before 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 thread src/wp-includes/media.php
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 thread src/wp-includes/media.php
Comment on lines +4719 to +4720
if ( isset( $meta['filesize'] ) && is_numeric( $meta['filesize'] ) && $meta['filesize'] > 0 ) {
$bytes = (int) $meta['filesize'];
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.

2 participants