Copilot commented on code in PR #3516:
URL: https://github.com/apache/brpc/pull/3516#discussion_r3950796067


##########
test/fuzzing/fuzz_rtmp.cpp:
##########
@@ -0,0 +1,79 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "brpc/policy/rtmp_protocol.h"
+#include "brpc/rtmp.h"
+#include "brpc/server.h"
+#include "butil/iobuf.h"
+#include "fuzz_common.h"
+
+#define kMinInputLength 5
+#define kMaxInputLength 4096
+
+namespace {
+
+class FuzzRtmpService : public brpc::RtmpService {
+public:
+    brpc::RtmpServerStream* NewStream(const brpc::RtmpConnectRequest&) 
override {
+        return nullptr;
+    }
+};
+
+brpc::Server* get_fuzz_server() {
+    static brpc::Server* started = []() -> brpc::Server* {
+        static FuzzRtmpService rtmp_service;
+        static brpc::Server server;
+        brpc::ServerOptions options;
+        options.rtmp_service = &rtmp_service;
+        if (server.Start(brpc::PortRange(20000, 29999), &options) != 0) {
+            // Fall back to a context with no service
+            LOG(ERROR) << "Fail to start fuzz RTMP server, "
+                          "server-side command handlers will be skipped";
+            return nullptr;
+        }
+
+        // Stop again straight away. _options -- and so rtmp_service -- is not
+        // touched by Stop()/Join()
+        server.Stop(0);
+        server.Join();
+        return &server;
+    }();
+    return started;
+}
+
+}  // namespace
+
+extern "C" int
+LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
+{
+    if (size < kMinInputLength || size > kMaxInputLength){
+        return 1;
+    }
+

Review Comment:
   LibFuzzer targets are expected to return 0; returning non-zero isn’t useful 
for rejecting inputs and can make behavior inconsistent across fuzzing 
engines/wrappers. Prefer `return 0;` when the input is out of range.



##########
test/fuzzing/oss-fuzz.sh:
##########
@@ -53,4 +53,5 @@ zip $OUT/fuzz_redis_seed_corpus.zip fuzz_redis_seed_corpus/*
 zip $OUT/fuzz_http_seed_corpus.zip  fuzz_http_seed_corpus/*
 zip $OUT/fuzz_butil_seed_corpus.zip fuzz_butil_seed_corpus/*
 zip $OUT/fuzz_hpack_seed_corpus.zip fuzz_hpack_seed_corpus/*
+zip $OUT/fuzz_rtmp_seed_corpus.zip  fuzz_rtmp_seed_corpus/*

Review Comment:
   This `zip ... fuzz_rtmp_seed_corpus/*` command will fail (non-zero exit) if 
the directory doesn’t exist or is empty (glob doesn’t match). In OSS-Fuzz 
builds (often running with `set -e`), that can break the build. Consider 
guarding the zip step (e.g., check the directory exists and has files) or using 
a zipping approach that tolerates empty corpora, and/or ensuring at least one 
seed file is present in `fuzz_rtmp_seed_corpus`.



##########
test/fuzzing/fuzz_rtmp.cpp:
##########
@@ -0,0 +1,79 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "brpc/policy/rtmp_protocol.h"
+#include "brpc/rtmp.h"
+#include "brpc/server.h"
+#include "butil/iobuf.h"
+#include "fuzz_common.h"
+
+#define kMinInputLength 5
+#define kMaxInputLength 4096
+
+namespace {
+

Review Comment:
   These are constants, but they’re defined as macros. Prefer `constexpr size_t 
kMinInputLength = ...;` / `constexpr size_t kMaxInputLength = ...;` to get type 
safety, avoid macro side effects, and keep the `k*` naming consistent with 
constant variables rather than preprocessor defines.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to