fix: saturate the process thread queue depth instead of overflowing

- process-thread-queue-depth is multiplied by the process thread
  count. A large depth overflowed the int, e.g.
  process-thread-queue-depth=1073741824 with 2 process threads, which
  is undefined behaviour.
- Cap the product at INT_MAX. The queue only counts free slots, so a
  depth that large is unbounded in practice, as asked for.
This commit is contained in:
Antonio SJ Musumeci 2026-11-21 18:12:38 -05:00
parent 127c2e6238
commit db9e991ebd
2 changed files with 11 additions and 4 deletions

View file

@ -17,6 +17,7 @@
#include "fuse_msgbuf.hpp"
#include <cassert>
#include <limits>
#include <memory>
#include <vector>
@ -270,7 +271,13 @@ _calculate_thread_counts(int *read_thread_count_,
if(*process_thread_queue_depth_ <= 0)
*process_thread_queue_depth_ = 2;
*process_thread_queue_depth_ *= std::abs(*process_thread_count_);
// Saturate rather than overflow. A total this large is unbounded in
// practice anyway since the queue only counts free slots.
if(*process_thread_queue_depth_ >
(std::numeric_limits<int>::max() / std::abs(*process_thread_count_)))
*process_thread_queue_depth_ = std::numeric_limits<int>::max();
else
*process_thread_queue_depth_ *= std::abs(*process_thread_count_);
}
int