diff --git a/lib/Controller/DownloadController.php b/lib/Controller/DownloadController.php index b4e939e8..9d69886a 100644 --- a/lib/Controller/DownloadController.php +++ b/lib/Controller/DownloadController.php @@ -133,10 +133,10 @@ class DownloadController extends GenericApiController // check if http_range is sent by browser $range = $this->request->getHeader('Range'); if (!empty($range)) { - [$sizeUnit, $rangeOrig] = explode('=', $range, 2); + [$sizeUnit, $rangeOrig] = Util::explode_exact('=', $range, 2); if ('bytes' === $sizeUnit) { // 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 $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); $seekStart = (empty($seekStart) || $seekEnd < abs((int) $seekStart)) ? 0 : max(abs((int) $seekStart), 0); diff --git a/lib/Util.php b/lib/Util.php index 18276121..4886f5d9 100644 --- a/lib/Util.php +++ b/lib/Util.php @@ -304,6 +304,20 @@ class Util 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. *