From a3ab971132b473ca20fa043950e0a995a626e608 Mon Sep 17 00:00:00 2001 From: rlaphoenix Date: Tue, 9 Jan 2024 02:45:10 +0000 Subject: [PATCH] Fix infinite loop in Track.get_init_segment If the Server returns a Content-Length Header with a value of 0, then the code near-after it would end up looping response streamed chunks of 0-length size, which would go on forever. --- devine/core/tracks/track.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/devine/core/tracks/track.py b/devine/core/tracks/track.py index 73e8215..8db2eef 100644 --- a/devine/core/tracks/track.py +++ b/devine/core/tracks/track.py @@ -186,9 +186,10 @@ class Track: else: size_test = session.head(url) if "Content-Length" in size_test.headers: - content_length = int(size_test.headers["Content-Length"]) - # use whichever is smaller in case this is a full file - content_length = min(content_length, maximum_size) + content_length_header = int(size_test.headers["Content-Length"]) + if content_length_header > 0: + # use whichever is smaller in case this is a large file + content_length = min(content_length_header, maximum_size) range_test = session.head(url, headers={"Range": "bytes=0-1"}) if range_test.status_code == 206: byte_range = f"0-{content_length-1}"