diff --git a/lib/inflate.js b/lib/inflate.js index e960a10..70e28ec 100644 --- a/lib/inflate.js +++ b/lib/inflate.js @@ -137,9 +137,6 @@ var Inflate = function(options) { } this.header = new gzheader(); - this.header.name_max = 65536; - this.header.comm_max = 65536; - this.header.extra_max = 65536; zlib_inflate.inflateGetHeader(this.strm, this.header); }; diff --git a/lib/zlib/gzheader.js b/lib/zlib/gzheader.js index d89781f..05a7dd5 100644 --- a/lib/zlib/gzheader.js +++ b/lib/zlib/gzheader.js @@ -14,16 +14,20 @@ function GZheader() { this.extra = null; /* extra field length (valid if extra != Z_NULL) */ this.extra_len = 0; + + /* setup limits is not necessary because in js we should not preallocate memory */ + /* for inflate use constant limit in 65536 bytes */ + /* space at extra (only when reading header) */ - this.extra_max = 0; + /*this.extra_max = 0;*/ /* pointer to zero-terminated file name or Z_NULL */ this.name = ''; /* space at name (only when reading header) */ - this.name_max = 0; + /*this.name_max = 0;*/ /* pointer to zero-terminated comment or Z_NULL */ this.comment = ''; /* space at comment (only when reading header) */ - this.comm_max = 0; + /*this.comm_max = 0;*/ /* true if there was or will be a header crc */ this.hcrc = 0; /* true when done reading gzip header (not used when writing a gzip file) */ diff --git a/lib/zlib/inflate.js b/lib/zlib/inflate.js index a35f314..b88019b 100644 --- a/lib/zlib/inflate.js +++ b/lib/zlib/inflate.js @@ -142,7 +142,6 @@ function InflateState() { this.ndist = 0; /* number of distance code lengths */ this.have = 0; /* number of code lengths in lens[] */ this.next = null; /* next available space in codes[] */ - this.next_index = 0; //unsigned short array //todo: test later with Uint16Array @@ -610,7 +609,9 @@ function inflate(strm, flush) { state.head.extra, input, next, - len + copy > state.head.extra_max - len ? state.head.extra_max : copy, + /* use constant limit because of extra field limitation in 65536 bytes */ + len + copy > 65536 - len ? 65536 : copy, + /*len + copy > state.head.extra_max - len ? state.head.extra_max : copy,*/ len ); //zmemcpy(state.head.extra + len, next, @@ -636,8 +637,9 @@ function inflate(strm, flush) { do { // TODO: 2 or 1 bytes? len = input[next + copy++]; + /* use constant limit because in js we should not preallocate memory */ if (state.head && len && - (state.length < state.head.name_max)) { + (state.length < 65536 /*state.head.name_max*/)) { state.head.name += String.fromCharCode(len); } } while (len && copy < have); @@ -661,8 +663,9 @@ function inflate(strm, flush) { copy = 0; do { len = input[next + copy++]; + /* use constant limit because in js we should not preallocate memory */ if (state.head && len && - (state.length < state.head.comm_max)) { + (state.length < 65536 /*state.head.comm_max*/)) { state.head.comment += String.fromCharCode(len); } } while (len && copy < have);