From 1f71f22f6d685a00d949e75bcd2bcc3434672d3d Mon Sep 17 00:00:00 2001 From: somepoi <46904988+somepoi@users.noreply.github.com> Date: Sun, 8 Mar 2026 20:26:23 +0300 Subject: [PATCH 1/2] fix: kafka docker container creation fix --- tools/common.just | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/common.just b/tools/common.just index b4bcc16..c4a38e7 100644 --- a/tools/common.just +++ b/tools/common.just @@ -27,8 +27,8 @@ build-windows: fetch-proto kafka-container-up: docker-compose up -d - MSYS_NO_PATHCONV=1 docker exec kafka /opt/kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 --create --topic moderation-result --replication-factor 1 --partitions 3 - MSYS_NO_PATHCONV=1 docker exec kafka /opt/kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 --create --topic moderation-request --replication-factor 1 --partitions 3 + MSYS_NO_PATHCONV=1 docker exec kafka /opt/kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 --create --topic moderation-result --replication-factor 1 --partitions 3 || true + MSYS_NO_PATHCONV=1 docker exec kafka /opt/kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 --create --topic moderation-request --replication-factor 1 --partitions 3 || true kafka-container-down: MSYS_NO_PATHCONV=1 docker exec kafka /opt/kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 --delete --topic moderation-request From 25b034dcae7a8e39c38173c28051a66b909eeaa2 Mon Sep 17 00:00:00 2001 From: somepoi <46904988+somepoi@users.noreply.github.com> Date: Sun, 8 Mar 2026 23:06:41 +0300 Subject: [PATCH 2/2] validation that key_str contains only digits --- src/moderationservice/kafka/kafkaclient.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/moderationservice/kafka/kafkaclient.cpp b/src/moderationservice/kafka/kafkaclient.cpp index e15e8e5..c174c24 100644 --- a/src/moderationservice/kafka/kafkaclient.cpp +++ b/src/moderationservice/kafka/kafkaclient.cpp @@ -195,10 +195,16 @@ void KafkaConsumer::ProcessMessage(RdKafka::Message* message) { std::string key_str(key_ptr, message->key_len()); + // Validate that key_str contains only digits (and optional leading +/-) + if (key_str.empty() || (!std::isdigit(key_str[0]) && key_str[0] != '-' && key_str[0] != '+')) { + std::cerr << "Invalid message key format (not numeric): '" << key_str << "'\n"; + return; + } + try { request_id = std::stoll(key_str); } catch (const std::exception& e) { - std::cerr << "Failed to parse message key to request ID: " << e.what() << "\n"; + std::cerr << "Failed to parse message key '" << key_str << "' to request ID: " << e.what() << "\n"; return; } }