Permalink
Browse files

fix HLIT, HDIST RLE bug #29

  • Loading branch information...
Yuta Imaya
Yuta Imaya committed Feb 20, 2014
1 parent 90e99ea commit 5d5efd17c71bc0381761f6577be3815aee7109cf
Showing with 12 additions and 3 deletions.
  1. +6 −2 src/rawinflate.js
  2. +6 −1 src/rawinflate_stream.js
View
@@ -52,6 +52,8 @@ Zlib.RawInflate = function(input, opt_params) {
this.bufferType = Zlib.RawInflate.BufferType.ADAPTIVE;
/** @type {boolean} resize flag for memory size optimization. */
this.resize = false;
+ /** @type {number} previous RLE value */
+ this.prev;
// option parameters
if (opt_params || !(opt_params = {})) {
@@ -484,7 +486,7 @@ Zlib.RawInflate.prototype.parseDynamicHuffmanBlock = function() {
/** @type {number} */
var code;
/** @type {number} */
- var prev;
+ var prev = this.prev;
/** @type {number} */
var repeat;
/** @type {number} */
@@ -514,6 +516,8 @@ Zlib.RawInflate.prototype.parseDynamicHuffmanBlock = function() {
}
}
+ this.prev = prev;
+
return lengths;
}
@@ -523,7 +527,7 @@ Zlib.RawInflate.prototype.parseDynamicHuffmanBlock = function() {
// distance code
distLengths = new (USE_TYPEDARRAY ? Uint8Array : Array)(hdist);
- //return;
+ this.prev = 0;
this.decodeHuffman(
buildHuffmanTable(decode.call(this, hlit, codeLengthsTable, litlenLengths)),
buildHuffmanTable(decode.call(this, hdist, codeLengthsTable, distLengths))
View
@@ -56,6 +56,8 @@ Zlib.RawInflateStream = function(input, ip, opt_buffersize) {
this.sp = 0; // stream pointer
/** @type {Zlib.RawInflateStream.Status} */
this.status = Zlib.RawInflateStream.Status.INITIALIZED;
+ /** @type {number} previous RLE value */
+ this.prev;
//
// backup
@@ -572,7 +574,7 @@ Zlib.RawInflateStream.prototype.parseDynamicHuffmanBlock = function() {
// decode function
function decode(num, table, lengths) {
var code;
- var prev;
+ var prev = this.prev;
var repeat;
var i = 0;
var bits;
@@ -613,6 +615,8 @@ Zlib.RawInflateStream.prototype.parseDynamicHuffmanBlock = function() {
}
}
+ this.prev = prev;
+
return lengths;
}
@@ -622,6 +626,7 @@ Zlib.RawInflateStream.prototype.parseDynamicHuffmanBlock = function() {
// distance code
distLengths = new (USE_TYPEDARRAY ? Uint8Array : Array)(hdist);
+ this.prev = 0;
this.litlenTable = buildHuffmanTable(decode.call(this, hlit, codeLengthsTable, litlenLengths));
this.distTable = buildHuffmanTable(decode.call(this, hdist, codeLengthsTable, distLengths));
}

0 comments on commit 5d5efd1

Please sign in to comment.