WordPress.org

Make WordPress Core

Opened 23 months ago

Closed 23 months ago

Last modified 16 months ago

#20984 closed defect (bug) (invalid)

XMLRPC: wp.uploadFile missing base64_decode

Reported by: fishc4ke Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.4
Component: XML-RPC Keywords:
Focuses: Cc:

Description

Uploading images via wp.uploadFile results in a broken image as the base64 bits are not decoded again.

Looking at the code, the file is written to disk by the function wp_upload_bits in functions.php.

A fix would be to alter line 1615 of functions.php:

@fwrite( $ifp, $bits );

to

@fwrite( $ifp, base64_decode($bits) );

However, I have not tested to see if this would break any other functionality.

Change History (7)

comment:1 maxcutler23 months ago

  • Cc maxcutler added

I am unable to reproduce this, can you please provide more details?

$bits is actually binary data by that point, since IXR_Message will call base64_decode before mw_newMediaObject (wp.uploadFile) is ever called. See L303 of wp-includes/class-IXR.php.

comment:2 fishc4ke23 months ago

The codex page states that bits' needs to be a base64-encoded, so I am simply opening the file and base64-encoding its contents (via Python 2.7.3) before uploading.

comment:3 maxcutler23 months ago

Can you supply the exact XML-RPC request you are sending to WordPress? If you are using the base64 value type as defined in the spec, then it should be doing the Right Thing.

If you are using Python's xmlrpclib, you can take a look at my python wrapper library to see the correct way to handle binary data.

comment:4 fishc4ke23 months ago

I've had another look at my code, found the issue. Bug in my code and as I was looking through the WP code I jumped to conclusions. tl;dr I'm an idiot.

comment:5 maxcutler23 months ago

  • Resolution set to invalid
  • Status changed from new to closed

comment:6 SergeyBiryukov23 months ago

  • Milestone Awaiting Review deleted

comment:7 SergeyBiryukov16 months ago

#23137 was marked as a duplicate.

Note: See TracTickets for help on using tickets.