Copilot commented on code in PR #3858:
URL: https://github.com/apache/avro/pull/3858#discussion_r3567609413


##########
lang/c/tests/test_avro_4293.c:
##########
@@ -0,0 +1,545 @@
+/*
+ * 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
+ *
+ * https://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.
+ */
+
+/*
+ * A bytes/string value is encoded as a length prefix followed by that many
+ * bytes of data. A malicious or truncated input can declare a huge length with
+ * little or no actual data, which previously caused a correspondingly huge
+ * allocation before the shortfall was noticed. When the reader knows how many
+ * bytes remain (a memory-backed reader), the declared length must be rejected
+ * before allocating for it.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+#include <errno.h>
+#include <avro.h>
+
+/* Portable set/unset of the collection-limit environment variable: MSVC has no
+ * setenv/unsetenv, so use _putenv_s (an empty value unsets the variable). */
+#ifdef _WIN32
+static void set_collection_limit(const char *value)
+{
+       _putenv_s("AVRO_MAX_COLLECTION_ITEMS", value);
+}
+static void unset_collection_limit(void)
+{
+       _putenv_s("AVRO_MAX_COLLECTION_ITEMS", "");
+}
+#else
+static void set_collection_limit(const char *value)
+{
+       setenv("AVRO_MAX_COLLECTION_ITEMS", value, 1);
+}
+static void unset_collection_limit(void)
+{
+       unsetenv("AVRO_MAX_COLLECTION_ITEMS");
+}
+#endif
+
+/* Decodes buf against the given schema and returns the avro_value_read rc.
+ * A non-zero rc means the read was rejected. */
+static int try_decode(avro_value_iface_t *iface, const char *buf, size_t 
buf_size)

Review Comment:
   The try_decode() header comment says it “returns the avro_value_read rc” and 
implies non-zero means the read was rejected, but the function also returns -1 
on setup failures (e.g., avro_generic_value_new or avro_reader_memory failing). 
Updating the comment avoids misleading future maintainers and makes test 
diagnostics clearer.



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

Reply via email to