From 9d9e9ce7faca455a76a8878a7c3c8bf3674c9211 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 4 Dec 2021 17:30:05 -0700 Subject: [PATCH] Update MediaStorageService, improve header parsing --- app/Services/MediaStorageService.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/app/Services/MediaStorageService.php b/app/Services/MediaStorageService.php index 4baa7cdf8..89d7ccdaa 100644 --- a/app/Services/MediaStorageService.php +++ b/app/Services/MediaStorageService.php @@ -43,18 +43,24 @@ class MediaStorageService { $h = $r->getHeaders(); - if (isset($h['Content-Length'], $h['Content-Type']) == false || - empty($h['Content-Length']) || - empty($h['Content-Type']) || - $h['Content-Length'] < 10 || - $h['Content-Length'] > (config_cache('pixelfed.max_photo_size') * 1000) - ) { + if (isset($h['Content-Length'], $h['Content-Type']) == false) { + return false; + } + + if(empty($h['Content-Length']) || empty($h['Content-Type']) ) { + return false; + } + + $len = is_array($h['Content-Length']) ? $h['Content-Length'][0] : $h['Content-Length']; + $mime = is_array($h['Content-Type']) ? $h['Content-Type'][0] : $h['Content-Type']; + + if($len < 10 || $len > ((config_cache('pixelfed.max_photo_size') * 1000))) { return false; } return [ - 'length' => $h['Content-Length'][0], - 'mime' => $h['Content-Type'][0] + 'length' => $len, + 'mime' => $mime ]; }