Copilot commented on code in PR #3516: URL: https://github.com/apache/brpc/pull/3516#discussion_r3921387771
########## test/fuzzing/fuzz_rtmp.cpp: ########## @@ -0,0 +1,44 @@ +// 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 "butil/iobuf.h" +#include "fuzz_common.h" + +#define kMinInputLength 5 +#define kMaxInputLength 4096 + +extern "C" int +LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + if (size < kMinInputLength || size > kMaxInputLength){ + return 1; + } + + std::string input(reinterpret_cast<const char*>(data), size); + butil::IOBuf buf; + buf.append(input); + Review Comment: The fuzzer currently copies the input into a `std::string` and then copies again into `butil::IOBuf`. You can append the raw bytes directly to `IOBuf` to avoid the extra allocation/copy, which matters for fuzzing throughput. ########## test/fuzzing/fuzz_rtmp.cpp: ########## @@ -0,0 +1,44 @@ +// 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 "butil/iobuf.h" +#include "fuzz_common.h" + +#define kMinInputLength 5 +#define kMaxInputLength 4096 + +extern "C" int +LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + if (size < kMinInputLength || size > kMaxInputLength){ + return 1; + } + + std::string input(reinterpret_cast<const char*>(data), size); + butil::IOBuf buf; + buf.append(input); + + brpc::Socket* sock = get_fuzz_socket(); + if (sock == nullptr) { + return 0; + } + + sock->reset_parsing_context(new brpc::policy::RtmpContext(nullptr, nullptr)); + brpc::policy::ParseRtmpMessage(&buf, sock, false, nullptr); Review Comment: `RtmpContext` is constructed with both `copt` and `server` as `nullptr`, but the type contract documents that exactly one side should be set to indicate client-side vs server-side context. Keeping both null makes the context role ambiguous and risks future null-dereferences if the socket ever becomes `CreatedByConnect()` (client-side) and code paths start using `_client_options`. Consider passing a long-lived default `RtmpClientOptions` (client-side) or, ideally, wiring a real `Server` with `ServerOptions.rtmp_service` and letting `ParseRtmpMessage` initialize the server-side context like production code does. -- 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]
