Skip to content

Commit

Permalink
[BUGFIX] Avoid returning invalid return type in AbstractOEmbedHelper
Browse files Browse the repository at this point in the history
"AbstractOEmbedHelper::getOEmbedData()" requests data and
decode it as json. json_decode() may fail and thus having
a invalid type decoded. In the complete chain this lead to
a "access array offset on value type bool" warning.

This patch checks the decoded value before returning, thus
ensure valid return type is "array" or "null". Furthermore
this avoids a signature change of the corresponding method
"AbstractOEmbedHelper::getOEmbedData()". Additionally this
paves the way for adding proper return type in a dedicated
patch. Streamline usage in VimeoHelper along the way.

Resolves: #97428
Releases: main, 11.5
Change-Id: Icda6b2baa88ddcbf070ceae75eafcb2e9ccb41f1
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/74353
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Oliver Bartsch <bo@cedev.de>
Tested-by: Stefan Bürk <stefan@buerk.tech>
  • Loading branch information
Oktopuce authored and sbuerk committed May 4, 2022
1 parent e909c16 commit ae00ad4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Expand Up @@ -65,13 +65,16 @@ protected function transformMediaIdToFile($mediaId, Folder $targetFolder, $fileE
*/
protected function getOEmbedData($mediaId)
{
$oEmbed = GeneralUtility::getUrl(
$oEmbed = (string)GeneralUtility::getUrl(
$this->getOEmbedUrl($mediaId)
);
if ($oEmbed) {
if ($oEmbed !== '') {
$oEmbed = json_decode($oEmbed, true);
if (is_array($oEmbed)) {
return $oEmbed;
}
}
return $oEmbed;
return null;
}

/**
Expand All @@ -87,7 +90,7 @@ public function getMetaData(File $file)

$oEmbed = $this->getOEmbedData($this->getOnlineMediaId($file));

if ($oEmbed) {
if (is_array($oEmbed) && $oEmbed !== []) {
$metadata['width'] = (int)$oEmbed['width'];
$metadata['height'] = (int)$oEmbed['height'];
if (empty($file->getProperty('title'))) {
Expand Down
Expand Up @@ -49,10 +49,12 @@ public function getPreviewImage(File $file)
$temporaryFileName = $this->getTempFolderPath() . 'vimeo_' . md5($videoId) . '.jpg';
if (!file_exists($temporaryFileName)) {
$oEmbedData = $this->getOEmbedData($videoId);
$previewImage = GeneralUtility::getUrl($oEmbedData['thumbnail_url']);
if ($previewImage !== false) {
file_put_contents($temporaryFileName, $previewImage);
GeneralUtility::fixPermissions($temporaryFileName);
if (!empty($oEmbedData['thumbnail_url'])) {
$previewImage = GeneralUtility::getUrl($oEmbedData['thumbnail_url']);
if ($previewImage !== false) {
file_put_contents($temporaryFileName, $previewImage);
GeneralUtility::fixPermissions($temporaryFileName);
}
}
}
return $temporaryFileName;
Expand Down

0 comments on commit ae00ad4

Please sign in to comment.