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


##########
test/fuzzing/fuzz_compress.cpp:
##########
@@ -0,0 +1,84 @@
+// 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.
+
+// Fuzz brpc's compression policies on the wire direction that servers are
+// attacked through: fuzz bytes are compressed with gzip/zlib (both window
+// styles) or snappy, and arbitrary fuzz bytes are also fed straight into the
+// decompressors (the hostile-compressed-payload model).

Review Comment:
   The comment and stated goal mention fuzzing gzip/zlib “both window styles” 
and feeding raw bytes to “every decompressor”, but case 4 only exercises gzip 
and snappy. To align behavior with intent and improve fuzz coverage, either add 
a `ZlibDecompress(in, &out)` call (clearing `out` between calls like the 
others), or update the comments to accurately reflect which decompressors are 
exercised in the hostile-payload mode.



##########
test/fuzzing/fuzz_compress.cpp:
##########
@@ -0,0 +1,84 @@
+// 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.
+
+// Fuzz brpc's compression policies on the wire direction that servers are
+// attacked through: fuzz bytes are compressed with gzip/zlib (both window
+// styles) or snappy, and arbitrary fuzz bytes are also fed straight into the
+// decompressors (the hostile-compressed-payload model).
+
+#include "butil/iobuf.h"
+#include "brpc/policy/gzip_compress.h"
+#include "brpc/policy/snappy_compress.h"
+

Review Comment:
   This file directly references `google::protobuf::io::GzipOutputStream::ZLIB` 
but does not include the protobuf header that defines `GzipOutputStream`. Even 
if it currently compiles via transitive includes, that’s brittle and can break 
with header refactors. Prefer adding the direct protobuf include that defines 
`GzipOutputStream` to make the dependency explicit.



##########
test/fuzzing/fuzz_compress.cpp:
##########
@@ -0,0 +1,84 @@
+// 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.
+
+// Fuzz brpc's compression policies on the wire direction that servers are
+// attacked through: fuzz bytes are compressed with gzip/zlib (both window
+// styles) or snappy, and arbitrary fuzz bytes are also fed straight into the
+// decompressors (the hostile-compressed-payload model).
+
+#include "butil/iobuf.h"
+#include "brpc/policy/gzip_compress.h"
+#include "brpc/policy/snappy_compress.h"
+
+extern "C" int
+LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+    if (size < 5) {
+        return 0;
+    }
+
+    const uint8_t mode = data[0] % 5;
+    butil::IOBuf in;
+    in.append(data + 1, size - 1);
+    butil::IOBuf mid;
+    butil::IOBuf out;
+
+    brpc::policy::GzipCompressOptions opts;
+    brpc::policy::GzipCompressOptions zlib_opts;
+    zlib_opts.format = google::protobuf::io::GzipOutputStream::ZLIB;

Review Comment:
   This file directly references `google::protobuf::io::GzipOutputStream::ZLIB` 
but does not include the protobuf header that defines `GzipOutputStream`. Even 
if it currently compiles via transitive includes, that’s brittle and can break 
with header refactors. Prefer adding the direct protobuf include that defines 
`GzipOutputStream` to make the dependency explicit.



##########
test/fuzzing/fuzz_compress.cpp:
##########
@@ -0,0 +1,84 @@
+// 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.
+
+// Fuzz brpc's compression policies on the wire direction that servers are
+// attacked through: fuzz bytes are compressed with gzip/zlib (both window
+// styles) or snappy, and arbitrary fuzz bytes are also fed straight into the
+// decompressors (the hostile-compressed-payload model).
+
+#include "butil/iobuf.h"
+#include "brpc/policy/gzip_compress.h"
+#include "brpc/policy/snappy_compress.h"
+
+extern "C" int
+LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+    if (size < 5) {
+        return 0;
+    }
+
+    const uint8_t mode = data[0] % 5;
+    butil::IOBuf in;
+    in.append(data + 1, size - 1);
+    butil::IOBuf mid;
+    butil::IOBuf out;
+
+    brpc::policy::GzipCompressOptions opts;
+    brpc::policy::GzipCompressOptions zlib_opts;
+    zlib_opts.format = google::protobuf::io::GzipOutputStream::ZLIB;
+    brpc::policy::GzipCompressOptions fast_opts;
+    fast_opts.compression_level = 1;
+
+    switch (mode) {
+    case 0: {
+        // gzip round-trip
+        if (brpc::policy::GzipCompress(in, &mid, &opts)) {
+            brpc::policy::GzipDecompress(mid, &out);
+        }
+        break;
+    }
+    case 1: {
+        // zlib round-trip
+        if (brpc::policy::GzipCompress(in, &mid, &zlib_opts)) {
+            brpc::policy::ZlibDecompress(mid, &out);
+        }
+        break;
+    }
+    case 2: {
+        // gzip with a different compression level
+        if (brpc::policy::GzipCompress(in, &mid, &fast_opts)) {
+            brpc::policy::GzipDecompress(mid, &out);
+        }
+        break;
+    }
+    case 3: {
+        // snappy round-trip
+        if (brpc::policy::SnappyCompress(in, &mid)) {
+            brpc::policy::SnappyDecompress(mid, &out);
+        }
+        break;
+    }
+    case 4: {
+        // hostile compressed payload: feed the raw fuzz bytes to every
+        // decompressor
+        brpc::policy::GzipDecompress(in, &out);
+        out.clear();

Review Comment:
   The comment and stated goal mention fuzzing gzip/zlib “both window styles” 
and feeding raw bytes to “every decompressor”, but case 4 only exercises gzip 
and snappy. To align behavior with intent and improve fuzz coverage, either add 
a `ZlibDecompress(in, &out)` call (clearing `out` between calls like the 
others), or update the comments to accurately reflect which decompressors are 
exercised in the hostile-payload mode.



##########
test/fuzzing/fuzz_compress.cpp:
##########
@@ -0,0 +1,84 @@
+// 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.
+
+// Fuzz brpc's compression policies on the wire direction that servers are
+// attacked through: fuzz bytes are compressed with gzip/zlib (both window
+// styles) or snappy, and arbitrary fuzz bytes are also fed straight into the
+// decompressors (the hostile-compressed-payload model).
+
+#include "butil/iobuf.h"
+#include "brpc/policy/gzip_compress.h"
+#include "brpc/policy/snappy_compress.h"
+
+extern "C" int
+LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+    if (size < 5) {
+        return 0;
+    }
+
+    const uint8_t mode = data[0] % 5;

Review Comment:
   The only hard requirement before reading `data[0]` is `size >= 1`, but the 
fuzzer currently discards inputs with `size < 5`. Unless there’s a specific 
reason to skip very small inputs, consider lowering this threshold to improve 
exploration of edge cases (e.g., empty/single-byte payload handling in the 
downstream decompressors).



-- 
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