Copilot commented on code in PR #3852:
URL: https://github.com/apache/avro/pull/3852#discussion_r3564678502
##########
lang/js/lib/files.js:
##########
@@ -145,6 +164,8 @@ function BlockDecoder(opts) {
this._type = null;
this._codecs = opts.codecs;
this._parseOpts = opts.parseOpts || {};
+ this._maxDecompressLength = opts.maxDecompressLength > 0 ?
+ opts.maxDecompressLength : getDefaultMaxDecompressLength();
Review Comment:
`opts.maxDecompressLength` is accepted as-is (any value `> 0`), which can
allow non-integer or out-of-range values to propagate into `zlib`'s
`maxOutputLength` option and trigger synchronous `RangeError`s. Normalize/clamp
the option the same way as the env-var default (finite positive integer,
bounded).
##########
lang/js/lib/files.js:
##########
@@ -58,6 +58,25 @@ var LONG_TYPE = schemas.createType('long');
// First 4 bytes of an Avro object container file.
var MAGIC_BYTES = Buffer.from('Obj\x01');
+// Default upper bound, in bytes, on the size a single data-file block may
+// decompress to. A block with a very high compression ratio (or a malformed
+// block) can otherwise expand to far more memory than its compressed size.
+// Mirrors the Java SDK's decompression limit (AVRO-4247). Overridable per
+// decoder via the `maxDecompressLength` option, or globally with the
+// `AVRO_MAX_DECOMPRESS_LENGTH` environment variable.
+var DEFAULT_MAX_DECOMPRESS_LENGTH = 200 * 1024 * 1024; // 200 MiB
+
+function getDefaultMaxDecompressLength() {
+ var value = process.env.AVRO_MAX_DECOMPRESS_LENGTH;
+ if (value !== undefined) {
+ var parsed = parseInt(value, 10);
+ if (!isNaN(parsed) && parsed > 0) {
+ return parsed;
+ }
+ }
+ return DEFAULT_MAX_DECOMPRESS_LENGTH;
+}
Review Comment:
`AVRO_MAX_DECOMPRESS_LENGTH` is parsed and returned without clamping to a
safe/valid range. If it is set to a very large or non-finite numeric value, the
resulting `maxOutputLength` passed to `zlib.inflateRaw` can be out of range and
may throw synchronously, potentially crashing the process at runtime. Clamp and
normalize the value (positive finite integer, bounded to
`Buffer.constants.MAX_LENGTH`) before using it.
--
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]