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.
This commit is contained in:
parent
6188c5a40f
commit
cb3bc3c493
3 changed files with 23 additions and 11 deletions
19
Libraries/LibIPC/Limits.h
Normal file
19
Libraries/LibIPC/Limits.h
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* Copyright (c) 2026, Andreas Kling <andreas@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Types.h>
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@
|
|||
#include <AK/Types.h>
|
||||
#include <LibCore/Socket.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibIPC/Limits.h>
|
||||
#include <LibIPC/TransportSocket.h>
|
||||
#include <LibThreading/Thread.h>
|
||||
|
||||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include <AK/Checked.h>
|
||||
#include <AK/Types.h>
|
||||
#include <LibIPC/HandleType.h>
|
||||
#include <LibIPC/Limits.h>
|
||||
#include <LibIPC/TransportSocketWindows.h>
|
||||
|
||||
#include <AK/Windows.h>
|
||||
|
|
@ -107,9 +108,6 @@ ErrorOr<void> TransportSocketWindows::duplicate_handles(Bytes bytes, Vector<size
|
|||
return {};
|
||||
}
|
||||
|
||||
// Maximum size of an IPC message payload (64 MiB should be more than enough)
|
||||
static constexpr size_t MAX_MESSAGE_SIZE = 64 * MiB;
|
||||
|
||||
// Maximum size of accumulated unprocessed bytes before we disconnect the peer
|
||||
static constexpr size_t MAX_UNPROCESSED_BUFFER_SIZE = 128 * MiB;
|
||||
|
||||
|
|
@ -206,8 +204,8 @@ TransportSocketWindows::ShouldShutdown TransportSocketWindows::read_as_many_mess
|
|||
while (index + sizeof(MessageHeader) <= m_unprocessed_bytes.size()) {
|
||||
MessageHeader header;
|
||||
memcpy(&header, m_unprocessed_bytes.data() + index, sizeof(MessageHeader));
|
||||
if (header.size > 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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue