Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#30394 closed defect (bug) (fixed)

Multiple edits with IMAGE_EDIT_OVERWRITE define enabled causes deletion of images

Reported by: hew's profile hew Owned by: wonderboymusic's profile wonderboymusic
Milestone: 4.2 Priority: normal
Severity: normal Version:
Component: Media Keywords: has-patch
Focuses: Cc:

Description (last modified by johnbillion)

The update_attached_file() call in wp_save_image() (wp-admin/includes/image-edit.php) fails when IMAGE_EDIT_OVERWRITE is enabled because the underlying update_meta_value() call has a meta_value (file path) that matches the value already in the DB.

$success = update_attached_file( $post_id, $new_path );

The failure there leads to subsequent file deletion at the end of wp_save_image().

@unlink( $delpath );

Likely related in some way: #30167

Attachments (3)

patch (789 bytes) - added by hew 9 years ago.
Poor man's attempt at a fix
patch2 (627 bytes) - added by hew 9 years ago.
Slightly less poor man fix
30394.diff (627 bytes) - added by wonderboymusic 9 years ago.

Download all attachments as: .zip

Change History (9)

@hew
9 years ago

Poor man's attempt at a fix

#1 @hew
9 years ago

Steps to reproduce:

  1. Set IMAGE_EDIT_OVERWRITE to true.
  2. Upload a new image.
  3. Edit the image and scale it once.
  4. Scale it again.
  5. The image should now be broken. If you check the file system while doing this, you should see the creation of an edit image file upon first scale and then deletion of it when you scale the second time.

#2 @hew
9 years ago

BTW, it's a little flaky as I play with it but it shouldn't be limited to just scaling operations. Cropping, rotating, etc seem to accomplish much of the same thing.

Anything that calls that update_meta_value() with the same meta_value.

@hew
9 years ago

Slightly less poor man fix

#3 @hew
9 years ago

Took another brief look at this tonight with less brain fuzzies. The first stab was a little silly; patch2 seems much saner.

#4 @johnbillion
9 years ago

  • Description modified (diff)
  • Keywords has-patch added
  • Milestone changed from Awaiting Review to Future Release

@wonderboymusic
9 years ago

#5 @wonderboymusic
9 years ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from new to closed

In 31043:

If IMAGE_EDIT_OVERWRITE is defined as true, ensure that multiple edits to the same image does not result in the file being deleted (updating the meta fails because the old and new paths are identical).

Props hew.
Fixes #30394.

#6 @ocean90
9 years ago

  • Milestone changed from Future Release to 4.2
Note: See TracTickets for help on using tickets.