@@ -164,6 +164,18 @@ void CWebCore::AddEventToEventQueue(std::function<void()> event, CWebView* pWebV
164164
165165 std::lock_guard<std::mutex> lock (m_EventQueueMutex);
166166
167+ // Prevent unbounded queue growth - drop oldest events if queue is too large
168+ if (m_EventQueue.size () >= MAX_EVENT_QUEUE_SIZE)
169+ {
170+ // Log warning even in release builds as this indicates a serious issue
171+ g_pCore->GetConsole ()->Printf (" WARNING: Browser event queue size limit reached (%d), dropping oldest events" , MAX_EVENT_QUEUE_SIZE);
172+
173+ // Remove oldest 10% of events to make room
174+ auto removeCount = MAX_EVENT_QUEUE_SIZE / 10 ;
175+ for (size_t i = 0 ; i < removeCount && !m_EventQueue.empty (); ++i)
176+ m_EventQueue.pop_front ();
177+ }
178+
167179#ifndef MTA_DEBUG
168180 m_EventQueue.push_back (EventEntry (event, pWebView));
169181#else
@@ -215,6 +227,22 @@ void CWebCore::WaitForTask(std::function<void(bool)> task, CWebView* webView)
215227 std::future<void > result;
216228 {
217229 std::scoped_lock lock (m_TaskQueueMutex);
230+
231+ // Prevent unbounded queue growth - if queue is too large, oldest tasks will be dropped during pulse
232+ if (m_TaskQueue.size () >= MAX_TASK_QUEUE_SIZE)
233+ {
234+ #ifdef MTA_DEBUG
235+ g_pCore->GetConsole ()->Printf (" Warning: Task queue size limit reached (%d), task will be aborted" , MAX_TASK_QUEUE_SIZE);
236+ #endif
237+ // Must still queue the task to fulfill the future, but it will be aborted during processing
238+ // Removing oldest task to make room
239+ if (!m_TaskQueue.empty ())
240+ {
241+ m_TaskQueue.front ().task (true ); // Abort oldest task
242+ m_TaskQueue.pop_front ();
243+ }
244+ }
245+
218246 m_TaskQueue.emplace_back (TaskEntry{task, webView});
219247 result = m_TaskQueue.back ().task .get_future ();
220248 }
@@ -358,13 +386,39 @@ void CWebCore::AddAllowedPage(const SString& strURL, eWebFilterType filterType)
358386{
359387 std::lock_guard<std::recursive_mutex> lock (m_FilterMutex);
360388
389+ // Prevent unbounded whitelist growth - remove old REQUEST entries if limit reached
390+ if (m_Whitelist.size () >= MAX_WHITELIST_SIZE)
391+ {
392+ // Remove WEBFILTER_REQUEST entries (temporary session entries)
393+ for (auto iter = m_Whitelist.begin (); iter != m_Whitelist.end ();)
394+ {
395+ if (iter->second .second == eWebFilterType::WEBFILTER_REQUEST)
396+ m_Whitelist.erase (iter++);
397+ else
398+ ++iter;
399+ }
400+ }
401+
361402 m_Whitelist[strURL] = std::pair<bool , eWebFilterType>(true , filterType);
362403}
363404
364405void CWebCore::AddBlockedPage (const SString& strURL, eWebFilterType filterType)
365406{
366407 std::lock_guard<std::recursive_mutex> lock (m_FilterMutex);
367408
409+ // Prevent unbounded whitelist growth - remove old REQUEST entries if limit reached
410+ if (m_Whitelist.size () >= MAX_WHITELIST_SIZE)
411+ {
412+ // Remove WEBFILTER_REQUEST entries (temporary session entries)
413+ for (auto iter = m_Whitelist.begin (); iter != m_Whitelist.end ();)
414+ {
415+ if (iter->second .second == eWebFilterType::WEBFILTER_REQUEST)
416+ m_Whitelist.erase (iter++);
417+ else
418+ ++iter;
419+ }
420+ }
421+
368422 m_Whitelist[strURL] = std::pair<bool , eWebFilterType>(false , filterType);
369423}
370424
0 commit comments