From 86c012c230b394f04e0d016bb5929438d14794a8 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Thu, 8 Oct 2020 21:09:52 -0700 Subject: Fixed #1021 preload count being max int triggers buffer overflow in getRecentDownloads() --- app/src/main/java/github/daneren2005/dsub/service/DownloadService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java index 77bc2516..67a0f36f 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java +++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java @@ -1083,7 +1083,7 @@ public class DownloadService extends Service { public synchronized List getRecentDownloads() { int from = Math.max(currentPlayingIndex - 10, 0); - int songsToKeep = Math.max(Util.getPreloadCount(this), 20); + int songsToKeep = Math.min(Math.max(Util.getPreloadCount(this), 20), downloadList.size()); int to = Math.min(currentPlayingIndex + songsToKeep, Math.max(downloadList.size() - 1, 0)); List temp = downloadList.subList(from, to); temp.addAll(backgroundDownloadList); -- cgit v1.2.3