Skip to content

Range Requests are not correctly handled for streaming large files #59159

@bogdan-dinu-me

Description

@bogdan-dinu-me

Symfony version(s) affected

6.4.x

Description

BinaryFileResponse returns Status 200 and no Content-Length or Content-Range headers when sending a request with "Range: bytes=0-".
I have a controller that sends large mp3 files for an html audio player. The audio file is loaded and starts playing in all browsers, but only Firefox allows seeking. Chrome and Edge just restart the audio when trying to seek.
I narroewed the issue to line 263 in BinaryFileResponse.php
} elseif ($end - $start < $fileSize - 1) {
Because $end is set to $fileSize -1 if not present in the Range header, the above condition will never be met.
Changing the above line to:
} elseif ($end - $start <= $fileSize - 1) {
Corrects the behaviour and the response from BinaryFileResponse is the same as from requesting a static file.

How to reproduce

Make a request from a web player for a large media file served by BinaryFileResponse. The server wil respond with Status 200 instead of Status 206 and proper headers.

Possible Solution

BinaryFileResponse.php (line 263):
} elseif ($end - $start <= $fileSize - 1) {

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy