iemejia commented on code in PR #3852:
URL: https://github.com/apache/avro/pull/3852#discussion_r3564712903
##########
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:
Fixed. AVRO_MAX_DECOMPRESS_LENGTH is now run through
normalizeMaxDecompressLength, which yields a positive finite integer bounded by
buffer.constants.MAX_LENGTH before it can reach zlib's maxOutputLength. Pushed
in 3cba108.
##########
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:
Fixed. opts.maxDecompressLength goes through the same normalizer as the
env-var default (finite positive integer, clamped to the max buffer length).
Added a test that an out-of-range limit is clamped rather than throwing. Pushed
in 3cba108.
--
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]