From cb3bc3c493daacb0c90637c31c367597a84bcf69 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 21 Jan 2026 22:07:14 +0100 Subject: [PATCH] LibIPC: Move IPC message limits to a shared Limits.h header This consolidates the message size and FD count limits into a single header file that can be used by both the encoding and decoding sides of the IPC layer. --- Libraries/LibIPC/Limits.h | 19 +++++++++++++++++++ Libraries/LibIPC/TransportSocket.cpp | 7 +------ Libraries/LibIPC/TransportSocketWindows.cpp | 8 +++----- 3 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 Libraries/LibIPC/Limits.h diff --git a/Libraries/LibIPC/Limits.h b/Libraries/LibIPC/Limits.h new file mode 100644 index 0000000000..a49e2121e7 --- /dev/null +++ b/Libraries/LibIPC/Limits.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2026, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace IPC { + +// Maximum size of an IPC message payload (64 MiB should be more than enough) +static constexpr size_t MAX_MESSAGE_PAYLOAD_SIZE = 64 * MiB; + +// Maximum number of file descriptors per message +static constexpr size_t MAX_MESSAGE_FD_COUNT = 128; + +} diff --git a/Libraries/LibIPC/TransportSocket.cpp b/Libraries/LibIPC/TransportSocket.cpp index a11491b2d8..e65cef01e2 100644 --- a/Libraries/LibIPC/TransportSocket.cpp +++ b/Libraries/LibIPC/TransportSocket.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -206,12 +207,6 @@ void TransportSocket::wait_until_readable() } } -// Maximum size of an IPC message payload (64 MiB should be more than enough) -static constexpr size_t MAX_MESSAGE_PAYLOAD_SIZE = 64 * MiB; - -// Maximum number of file descriptors per message -static constexpr size_t MAX_MESSAGE_FD_COUNT = 128; - // Maximum size of accumulated unprocessed bytes before we disconnect the peer static constexpr size_t MAX_UNPROCESSED_BUFFER_SIZE = 128 * MiB; diff --git a/Libraries/LibIPC/TransportSocketWindows.cpp b/Libraries/LibIPC/TransportSocketWindows.cpp index e9b08e1141..73387d6f4a 100644 --- a/Libraries/LibIPC/TransportSocketWindows.cpp +++ b/Libraries/LibIPC/TransportSocketWindows.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -107,9 +108,6 @@ ErrorOr TransportSocketWindows::duplicate_handles(Bytes bytes, Vector MAX_MESSAGE_SIZE) { - dbgln("TransportSocketWindows: Rejecting message with size {} exceeding limit {}", header.size, MAX_MESSAGE_SIZE); + if (header.size > MAX_MESSAGE_PAYLOAD_SIZE) { + dbgln("TransportSocketWindows: Rejecting message with size {} exceeding limit {}", header.size, MAX_MESSAGE_PAYLOAD_SIZE); should_shutdown = ShouldShutdown::Yes; break; }