From 629c63f3bf58a53ede9ac5cca3ef3156a7266af0 Mon Sep 17 00:00:00 2001 From: Lucas Vieira Date: Fri, 27 Mar 2026 00:24:20 -0300 Subject: [PATCH 1/2] refactor: switch admin create_queue from protobuf to binary encoding test admin client now uses binary wire format for create_queue (queue_len:u16 + queue + on_enqueue_len:u16 + on_failure_len:u16 + visibility_timeout_ms:u32) instead of hand-encoded protobuf. replace writeVarint with writeU16/writeU32 helpers. --- .../java/dev/faisca/fila/FibpAdminClient.java | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/test/java/dev/faisca/fila/FibpAdminClient.java b/src/test/java/dev/faisca/fila/FibpAdminClient.java index 0ac10fe..7d4ce39 100644 --- a/src/test/java/dev/faisca/fila/FibpAdminClient.java +++ b/src/test/java/dev/faisca/fila/FibpAdminClient.java @@ -19,9 +19,8 @@ /** * Minimal FIBP admin client for test infrastructure. * - *

Supports CreateQueue only. Admin operation payloads are protobuf-encoded (matching the - * server's fila-core admin dispatch). We hand-roll the minimal protobuf needed to avoid a test - * dependency on a protobuf runtime. + *

Supports CreateQueue only. Admin operation payloads use binary encoding (same wire format as + * data ops). * *

Supports both plaintext and TLS/mTLS connections. */ @@ -133,26 +132,32 @@ private void authenticate(String apiKey) throws IOException { } /** - * Encode a CreateQueueRequest protobuf message with just the name field. + * Encode a CreateQueue request using the binary wire format. * - *

Protobuf encoding: field 1 (name, string) = tag 0x0A (field=1, wire_type=2) + varint(len) + - * utf8 bytes. + *

Wire format: queue_len:u16 + queue:utf8 + on_enqueue_len:u16 + on_enqueue:utf8 + + * on_failure_len:u16 + on_failure:utf8 + visibility_timeout_ms:u32 */ private static byte[] encodeCreateQueueRequest(String name) { byte[] nameBytes = name.getBytes(StandardCharsets.UTF_8); ByteArrayOutputStream buf = new ByteArrayOutputStream(); - buf.write(0x0A); // field 1, wire type 2 (length-delimited) - writeVarint(buf, nameBytes.length); + writeU16(buf, nameBytes.length); buf.write(nameBytes, 0, nameBytes.length); + writeU16(buf, 0); // on_enqueue: empty + writeU16(buf, 0); // on_failure: empty + writeU32(buf, 0); // visibility_timeout_ms: 0 return buf.toByteArray(); } - private static void writeVarint(ByteArrayOutputStream buf, int value) { - while ((value & ~0x7F) != 0) { - buf.write((value & 0x7F) | 0x80); - value >>>= 7; - } - buf.write(value); + private static void writeU16(ByteArrayOutputStream buf, int value) { + buf.write((value >> 8) & 0xFF); + buf.write(value & 0xFF); + } + + private static void writeU32(ByteArrayOutputStream buf, int value) { + buf.write((value >> 24) & 0xFF); + buf.write((value >> 16) & 0xFF); + buf.write((value >> 8) & 0xFF); + buf.write(value & 0xFF); } private static KeyManagerFactory buildKeyManagerFactory(byte[] certPem, byte[] keyPem) From bb8683f7017b8b6c2324c63b4be7a19eba1e9fa8 Mon Sep 17 00:00:00 2001 From: Lucas Vieira Date: Fri, 27 Mar 2026 00:40:31 -0300 Subject: [PATCH 2/2] fix: validate queue name utf-8 length before writing u16 in createqueue names whose utf-8 encoding exceeds 65535 bytes would silently overflow the u16 length field. now throws ioexception with a clear message. --- src/test/java/dev/faisca/fila/FibpAdminClient.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/test/java/dev/faisca/fila/FibpAdminClient.java b/src/test/java/dev/faisca/fila/FibpAdminClient.java index 7d4ce39..18627fc 100644 --- a/src/test/java/dev/faisca/fila/FibpAdminClient.java +++ b/src/test/java/dev/faisca/fila/FibpAdminClient.java @@ -137,8 +137,12 @@ private void authenticate(String apiKey) throws IOException { *

Wire format: queue_len:u16 + queue:utf8 + on_enqueue_len:u16 + on_enqueue:utf8 + * on_failure_len:u16 + on_failure:utf8 + visibility_timeout_ms:u32 */ - private static byte[] encodeCreateQueueRequest(String name) { + private static byte[] encodeCreateQueueRequest(String name) throws IOException { byte[] nameBytes = name.getBytes(StandardCharsets.UTF_8); + if (nameBytes.length > 0xFFFF) { + throw new IOException( + "queue name too long: UTF-8 length " + nameBytes.length + " exceeds u16 max (65535)"); + } ByteArrayOutputStream buf = new ByteArrayOutputStream(); writeU16(buf, nameBytes.length); buf.write(nameBytes, 0, nameBytes.length);