ui: bound the input history size.

Only the lower end was checked, so a large value threw bad_alloc and exited.
This commit is contained in:
xirvik
2026-08-08 16:48:10 +00:00
committed by Jari Sundell
parent 161a36dedd
commit 44bb2d691f
2 changed files with 9 additions and 2 deletions
+4 -2
View File
@@ -4,6 +4,7 @@
#include <fstream>
#include <stdexcept>
#include <string>
#include <string.h>
#include <torrent/throttle.h>
#include <torrent/torrent.h>
@@ -354,8 +355,9 @@ Root::reset_input_history_attributes(ui::DownloadList::Input type) {
void
Root::set_input_history_size(int size) {
if (size < 1)
throw torrent::input_error("Invalid input history size.");
if (size < 1 || size > max_input_history_size)
throw torrent::input_error("Input history size must be between 1 and " +
std::to_string(max_input_history_size) + ".");
for (auto& [entry, category] : m_input_history) {
// Reserve the latest input history entries if new size is smaller than original.
+5
View File
@@ -54,6 +54,11 @@ public:
typedef std::vector<std::string> InputHistoryCategory;
typedef std::map<int, InputHistoryCategory> InputHistory;
// Every category holds this many entries, and the whole history is written to
// and read back from the session, so the useful range ends long before the
// point where resizing it becomes a memory problem.
static constexpr int max_input_history_size = 4096;
Root();
void init(Control* c);