class UploadStash {
// Format of the key for files -- has to be suitable as a filename itself (e.g. ab12cd34ef.jpg)
const KEY_FORMAT_REGEX = '/^[\w-\.]+\.\w*$/';
+ const MAX_US_PROPS_SIZE = 65535;
/**
* repository that this uses to store temp files
// If no key was supplied, make one. a mysql insertid would be totally
// reasonable here, except that for historical reasons, the key is this
// random thing instead. At least it's not guessable.
- //
// Some things that when combined will make a suitably unique key.
// see: http://www.jwz.org/doc/mid.html
list( $usec, $sec ) = explode( ' ', microtime() );
$usec = substr( $usec, 2 );
- $key = wfBaseConvert( $sec . $usec, 10, 36 ) . '.' .
- wfBaseConvert( mt_rand(), 10, 36 ) . '.' .
+ $key = Wikimedia\base_convert( $sec . $usec, 10, 36 ) . '.' .
+ Wikimedia\base_convert( mt_rand(), 10, 36 ) . '.' .
$this->userId . '.' .
$extension;
wfDebug( __METHOD__ . " inserting $stashPath under $key\n" );
$dbw = $this->repo->getMasterDb();
+ $serializedFileProps = serialize( $fileProps );
+ if ( strlen( $serializedFileProps ) > self::MAX_US_PROPS_SIZE ) {
+ // Database is going to truncate this and make the field invalid.
+ // Prioritize important metadata over file handler metadata.
+ // File handler should be prepared to regenerate invalid metadata if needed.
+ $fileProps['metadata'] = false;
+ $serializedFileProps = serialize( $fileProps );
+ }
+
$this->fileMetadata[$key] = array(
'us_id' => $dbw->nextSequenceValue( 'uploadstash_us_id_seq' ),
'us_user' => $this->userId,
'us_key' => $key,
'us_orig_path' => $path,
'us_path' => $stashPath, // virtual URL
- 'us_props' => $dbw->encodeBlob( serialize( $fileProps ) ),
+ 'us_props' => $dbw->encodeBlob( $serializedFileProps ),
'us_size' => $fileProps['size'],
'us_sha1' => $fileProps['sha1'],
'us_mime' => $fileProps['mime'],