iemejia commented on code in PR #3853:
URL: https://github.com/apache/avro/pull/3853#discussion_r3567494170
##########
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:
Fixed — a positive overflow (strtoll ERANGE returning LLONG_MAX) now clamps
to the maximum usable cap (min of INT64_MAX and SIZE_MAX) instead of falling
back to the 200 MiB default, so a very large 'max' value no longer reduces the
effective limit.
--
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]