From 758a51dfb9f8c5bc2cf2471caf5b8c0875467971 Mon Sep 17 00:00:00 2001 From: Andrew Cain Date: Thu, 1 Aug 2024 23:34:21 +1000 Subject: [PATCH] fix: avoid attempts to read negative size in file stream helper --- app/helpers/file_stream_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/file_stream_helper.rb b/app/helpers/file_stream_helper.rb index 6859954d6..1644b3fe4 100644 --- a/app/helpers/file_stream_helper.rb +++ b/app/helpers/file_stream_helper.rb @@ -40,7 +40,7 @@ def stream_file(file_path) end # Return the requested content - content_length = end_point - begin_point + 1 + content_length = [end_point - begin_point + 1, 0].max # Ensure we don't attempt to read a negative length header['Access-Control-Expose-Headers'] = header.key?('Content-Disposition') ? 'Content-Disposition,Content-Range,Accept-Ranges' : 'Content-Range,Accept-Ranges' header['Content-Range'] = "bytes #{begin_point}-#{end_point}/#{file_size}" header['Content-Length'] = content_length.to_s