Deduplicate protocol constants

This commit is contained in:
p
2026-09-28 21:26:27 +02:00
parent f479147131
commit 84a896bb3d
2 changed files with 7 additions and 8 deletions
+3 -4
View File
@@ -26,7 +26,6 @@ namespace proto = dawn::ipc::imaged;
// --- Jobs --------------------------------------------------------------------
static constexpr char kService[] = "imaged";
static constexpr uint64_t kMaxBlob = 1024ull * 1024 * 1024;
static vector<byte>
error_frame(uint64_t id, string message, dawn::ipc::ErrorCode code)
@@ -88,7 +87,7 @@ decode_job(const Job &job)
dawn::ipc::ErrorCode::InvalidArgument);
return reply;
}
if (image->data.empty() || image->data.size() > kMaxBlob) {
if (image->data.empty() || image->data.size() > proto::kImagedMaxBlobSize) {
reply.payload = error_frame(job.request, "decoded pixmap is too large",
dawn::ipc::ErrorCode::InvalidArgument);
return reply;
@@ -167,8 +166,8 @@ handle_payload(State &state, uint64_t connection, span<const byte> payload,
auto job = make_shared<Job>();
job->request = request->request.id;
span<const byte> data;
if (const char *failure = dawn::ipc::take_blob(
request_decode.data, owned, kMaxBlob, data, job->shared))
if (const char *failure = dawn::ipc::take_blob(request_decode.data, owned,
proto::kImagedMaxBlobSize, data, job->shared))
return invalid(failure);
if (!job->shared.ok())
job->data.assign(data.begin(), data.end());
+4 -4
View File
@@ -25,7 +25,6 @@ namespace proto = dawn::ipc::thumbd;
// --- Jobs --------------------------------------------------------------------
static constexpr char kService[] = "thumbd";
static constexpr uint64_t kMaxBlob = 1024ull * 1024 * 1024;
static vector<byte>
error_frame(uint64_t id, string message, dawn::ipc::ErrorCode code)
@@ -154,11 +153,12 @@ handle_payload(State &state, uint64_t connection, span<const byte> payload,
job->height > dawn::kMaxDimension || !job->out_width ||
!job->out_height || job->out_width > dawn::kMaxDimension ||
job->out_height > dawn::kMaxDimension || job->stride < row ||
uint64_t(job->out_width) * job->out_height * 4 > kMaxBlob)
uint64_t(job->out_width) * job->out_height * 4 >
proto::kThumbdMaxBlobSize)
return invalid("invalid image geometry");
span<const byte> pixels;
if (const char *failure = dawn::ipc::take_blob(
scale.source.pixels, owned, kMaxBlob, pixels, job->shared))
if (const char *failure = dawn::ipc::take_blob(scale.source.pixels, owned,
proto::kThumbdMaxBlobSize, pixels, job->shared))
return invalid(failure);
if (uint64_t(job->stride) * job->height > pixels.size())
return invalid("pixel blob is too small");