Make WordPress Core

Opened 9 years ago

Last modified 22 months ago

#32318 new defect (bug)

Upload fails, wp_insert_attachment returned 0

Reported by: programmin's profile programmin Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.1.5
Component: Upload Keywords: close dev-feedback
Focuses: administration Cc:

Description

One specific mp3 file was failing to attach, and it seems wp_insert_attachment is breaking with 0 returned, breaking update-attachment-metadata:

wp-admin/includes/media.php, line 360:

    // Save the data
    $id = wp_insert_attachment($attachment, $file, $post_id);
    if ( !is_wp_error($id) ) {
        wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
    }
  


id = 0, caused by these lines in wp-includes/post.php, around line 3351:

if ( false === $wpdb->insert( $wpdb->posts, $data ) ) {
            if ( $wp_error ) {
                return new WP_Error('db_insert_error', __('Could not insert post into the database'), $wpdb->last_error);
            } else {
                return 0;
            }
        }
      


In this case the documentation is wrong, it didn't return the post id.

Attachments (1)

sermon-050315b(1).mp3 (9.1 MB) - added by programmin 9 years ago.
problematic mp3 example

Change History (13)

#1 @programmin
9 years ago

Any ideas? IIRC this behavior has happened before with another specific file not able to upload to a Wordpress blog.

#2 @programmin
9 years ago

I'm seeing the same behavior in Wordpress 4.3. It adds it to the server, but fails before adding it to media library.

@programmin
9 years ago

problematic mp3 example

#3 @programmin
9 years ago

Perhaps I should rephrase this bug - I have to wonder if there is any wordpress install that does not have problems with that mp3, and many similar ones. On sites that have no problem uploading various file types and mp3s, this type of file fails, always. So, is there some option that I happen to have enabled, or some mp3-tag library that happened to be out of date on all systems I tried on?

This is happening on 4.3.2 preview as well.

#4 @programmin
9 years ago

If you add a var_dump($data) before that return 0 you will see that on files this fails on there's weird metadata like "Genre: ÿþ." Is this a misconfiguration of id3 reader you are using?

At the very least can have an error message that says this file has unrecognized metadata and wasn't saved to the database, and remove the file from the server since it didn't get added to the media library?

#5 @programmin
9 years ago

This is still happening in Wordpress 4.4 beta, by the way - some mp3s upload fine, the one attached above, and many similar ones, will never appear in the media modal after uploading, "An error occurred in the upload. Please try again later."

This is happening the same on two different sites with two different themes, running 4.4 beta.

#6 @programmin
9 years ago

FYI still happening in WP 4.4.1. Is there anything further I should do to track down the problem?

#7 @chriscct7
9 years ago

  • Focuses administration added
  • Keywords close added

It appears the mp3 file you uploaded contains invalid headers. While it may play on some devices, by definition of spec it is not a valid mp3 file (similar to how an HTML document that can render in a browser doesn't necessarily have to pass the w3c HTML validity checker). Attempted validation of the file's format fails on several open source mp3 file validity checkers, such as Checkmate MP3 checker.

This ticket was mentioned in Slack in #core by chriscct7. View the logs.


9 years ago

#9 @programmin
9 years ago

Thank you, I hadn't heard about that program for checking mp3 files! Even so it seems really bad that mp3 files could be uploaded successfully, then just fail with an error when the file is still taking space on the server. If user does this repeatedly for large files it could be very bad. Can't this be handled better in cases like this?

#10 @desrosj
5 years ago

  • Keywords dev-feedback added

@joemcgill @mikeschroder Are you aware of any way this can be handled a bit better?

#11 @joemcgill
5 years ago

It looks like the documentation for wp_insert_attachment() have since been updated to account for the case of 0 being returned.

We could attempt to have a garbage collection job for files that are successfully uploaded, but fail to be inserted to the database, maybe? I agree that this is currently not ideal.

This ticket was mentioned in Slack in #core-media by joedolson. View the logs.


22 months ago

Note: See TracTickets for help on using tickets.