Update MediaStorageService, improve header parsing

This commit is contained in:
Daniel Supernault 2021-12-04 17:30:05 -07:00
parent 2aa73c1ffa
commit 9d9e9ce7fa
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -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
];
}