Skip to content

Commit

Permalink
Allow URI as data for vcard PHOTO
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Dec 17, 2018
1 parent c4a9bd1 commit 075db3f
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions apps/dav/lib/CardDAV/PhotoCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use OCP\Files\SimpleFS\ISimpleFolder;
use Sabre\CardDAV\Card;
use Sabre\VObject\Property\Binary;
use Sabre\VObject\Property\Uri;
use Sabre\VObject\Reader;

class PhotoCache {
Expand Down Expand Up @@ -193,19 +194,23 @@ private function getPhoto(Card $node) {
}

$photo = $vObject->PHOTO;
$type = $this->getType($photo);

$val = $photo->getValue();

// handle data URI. e.g PHOTO;VALUE=URI:data:image/jpeg;base64,/9j/4AAQSkZJRgABAQE
if ($photo->getValueType() === 'URI') {
$parsed = \Sabre\URI\parse($val);
//only allow data://

// only allow data://
if ($parsed['scheme'] !== 'data') {
return false;
}
if (substr_count($parsed['path'], ';') === 1) {
list($type,) = explode(';', $parsed['path']);
}
$val = file_get_contents($val);
} else {
// get type if binary data
$type = $this->getBinaryType($photo);
}

$allowedContentTypes = [
Expand Down Expand Up @@ -240,7 +245,7 @@ private function readCard($cardData) {
* @param Binary $photo
* @return string
*/
private function getType(Binary $photo) {
private function getBinaryType(Binary $photo) {
$params = $photo->parameters();
if (isset($params['TYPE']) || isset($params['MEDIATYPE'])) {
/** @var Parameter $typeParam */
Expand Down

0 comments on commit 075db3f

Please sign in to comment.