download: fix invalid destructuring in range (fix #590)

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/602/head
Varun Patil 2023-04-19 16:32:29 -07:00
parent 6fb4b4dd23
commit da192ee70e
2 changed files with 17 additions and 3 deletions

View File

@ -133,10 +133,10 @@ class DownloadController extends GenericApiController
// check if http_range is sent by browser // check if http_range is sent by browser
$range = $this->request->getHeader('Range'); $range = $this->request->getHeader('Range');
if (!empty($range)) { if (!empty($range)) {
[$sizeUnit, $rangeOrig] = explode('=', $range, 2); [$sizeUnit, $rangeOrig] = Util::explode_exact('=', $range, 2);
if ('bytes' === $sizeUnit) { if ('bytes' === $sizeUnit) {
// http://tools.ietf.org/id/draft-ietf-http-range-retrieval-00.txt // http://tools.ietf.org/id/draft-ietf-http-range-retrieval-00.txt
[$range, $extra] = explode(',', $rangeOrig, 2); [$range, $extra] = Util::explode_exact(',', $rangeOrig, 2);
} }
} }
@ -147,7 +147,7 @@ class DownloadController extends GenericApiController
// Get file reading parameters // Get file reading parameters
$size = $file->getSize(); $size = $file->getSize();
[$seekStart, $seekEnd] = explode('-', $range, 2); [$seekStart, $seekEnd] = Util::explode_exact('-', $range, 2);
$seekEnd = (empty($seekEnd)) ? ($size - 1) : min(abs((int) $seekEnd), $size - 1); $seekEnd = (empty($seekEnd)) ? ($size - 1) : min(abs((int) $seekEnd), $size - 1);
$seekStart = (empty($seekStart) || $seekEnd < abs((int) $seekStart)) ? 0 : max(abs((int) $seekStart), 0); $seekStart = (empty($seekStart) || $seekEnd < abs((int) $seekStart)) ? 0 : max(abs((int) $seekStart), 0);

View File

@ -304,6 +304,20 @@ class Util
return mb_ereg_replace('\/\/+', '/', $path); // remove extra slashes return mb_ereg_replace('\/\/+', '/', $path); // remove extra slashes
} }
/**
* Explode a string into fixed number of components.
*
* @param string $delimiter Delimiter
* @param string $string String to explode
* @param int $count Number of components
*
* @return string[] Array of components
*/
public static function explode_exact(string $delimiter, string $string, int $count): array
{
return array_pad(explode($delimiter, $string, $count), $count, '');
}
/** /**
* Get a system config key with the correct default. * Get a system config key with the correct default.
* *