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


##########
lang/c/src/codec.c:
##########
@@ -43,9 +44,52 @@
 #include "avro/errors.h"
 #include "avro/allocation.h"
 #include "codec.h"
+#include <errno.h>
+#include <limits.h>
+#include <stdint.h>
 
 #define DEFAULT_BLOCK_SIZE     (16 * 1024)
 
+/*
+ * When reading a data file, each block is decompressed according to the file's
+ * codec. A block with a very high compression ratio (or a malformed block) can
+ * expand to far more memory than its compressed size. To guard against
+ * unbounded allocation, the decompressed size of a single block is capped. 
This
+ * mirrors the Java SDK's decompression limit (AVRO-4247). The default can be
+ * overridden with the AVRO_MAX_DECOMPRESS_LENGTH environment variable.
+ */
+#define AVRO_DEFAULT_MAX_DECOMPRESS_LENGTH     ((int64_t) 200 * 1024 * 1024)  
/* 200 MiB */
+
+static int64_t
+avro_max_decompress_length(void)
+{
+       const char *env = getenv("AVRO_MAX_DECOMPRESS_LENGTH");
+       if (env != NULL && *env != '\0') {
+               char *end = NULL;
+               errno = 0;
+               long long value = strtoll(env, &end, 10);
+               if (errno == 0 && end != NULL && *end == '\0' && value > 0) {

Review Comment:
   `avro_max_decompress_length()` currently ignores values that overflow 
`strtoll()` (errno==ERANGE) and falls back to the default 200 MiB. That means 
setting `AVRO_MAX_DECOMPRESS_LENGTH` to a value just above `LLONG_MAX` (or 
otherwise out of range) unexpectedly *reduces* the effective limit instead of 
clamping to the maximum representable value, which is surprising for a “max” 
configuration knob.



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