[wp-trac] [WordPress Trac] #47296: Attachments with very long filenames fail to save to the database

WordPress Trac noreply at wordpress.org
Thu May 16 17:51:39 UTC 2019


#47296: Attachments with very long filenames fail to save to the database
--------------------------+-----------------------------
 Reporter:  mboynes       |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Upload        |    Version:  5.2
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 When an attachment is uploaded and the `attachment` post is inserted into
 the database, the `guid` is set to the attachment URL. The `guid` database
 column is limited to 255 characters, so a very long domain/filename
 combination can result in the post failing to save to the database with
 the vague message "Could not insert post into the database". The uploaded
 file does not get deleted from the uploads directory, and further attempts
 to upload the same file without renaming it will result in a different
 error, "The uploaded file could not be moved to {location}".

 The issue occurs in `wpdb::strip_invalid_text()` and
 `wpdb::process_fields()`. `wpdb::strip_invalid_text()` trims the field
 contents down to 255 characters, and `wpdb::process_fields()` fails as a
 result of this data change.

 The root cause is the same as #32315, though I believe this should still
 be tracked and handled separately. Judging by the trajectory of #32315,
 the user would be presented with a cryptic database-focused error message,
 whereas a better solution for this problem would be that the attachment
 successfully inserts.

 === To Replicate

 1. Create a file and give it a name composed of 240+ characters (the
 "tipping point" length depends on the site's domain, amongst other
 factors, so this error can occur with shorter filenames).
 2. Upload the file to WordPress anywhere media can be added.
 3. The database insert should have failed with the error message, "Could
 not insert post into the database".
 4. Attempt to upload the same file again to observe the error message,
 "The uploaded file could not be moved to..."

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/47296>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list