Description
In app/services/media_server.py (~line 23), the build_range_response function parses range requests using a simple string split:
range_spec = range_header.replace("bytes=", "").strip()
parts = range_spec.split("-")
start = int(parts[0]) if parts[0] else 0
end = int(parts[1]) if len(parts) > 1 and parts[1] else file_size - 1
If a client requests the last 500 bytes using the standard suffix-byte-range format bytes=-500, parts evaluates to ["", "500"].
Because parts[0] is empty, start is erroneously set to 0, and end becomes 500.
This results in the server returning the first 501 bytes instead of the last 500 bytes, which breaks clients that attempt to seek to the end of a file or read trailing metadata.
Suggested Fix
Check if parts[0] is empty and parts[1] is present. If so, calculate the start offset from the end of the file:
if not parts[0] and len(parts) > 1 and parts[1]:
start = max(0, file_size - int(parts[1]))
end = file_size - 1
File Path
app/services/media_server.py
Description
In
app/services/media_server.py(~line 23), thebuild_range_responsefunction parses range requests using a simple string split:If a client requests the last 500 bytes using the standard suffix-byte-range format
bytes=-500,partsevaluates to["", "500"].Because
parts[0]is empty,startis erroneously set to0, andendbecomes500.This results in the server returning the first 501 bytes instead of the last 500 bytes, which breaks clients that attempt to seek to the end of a file or read trailing metadata.
Suggested Fix
Check if
parts[0]is empty andparts[1]is present. If so, calculate the start offset from the end of the file:File Path
app/services/media_server.py