Commit ae00ad42 authored by Florian Rival's avatar Florian Rival Committed by Stefan Bürk
Browse files

[BUGFIX] Avoid returning invalid return type in AbstractOEmbedHelper

"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's avatarOliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Tested-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
parent e909c163
......@@ -65,13 +65,16 @@ abstract class AbstractOEmbedHelper extends AbstractOnlineMediaHelper
*/
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;
}
/**
......@@ -87,7 +90,7 @@ abstract class AbstractOEmbedHelper extends AbstractOnlineMediaHelper
$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'))) {
......
......@@ -49,10 +49,12 @@ class VimeoHelper extends AbstractOEmbedHelper
$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;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment