Skip to content

RawDeflate with FIXED or NONE mode doesn't work well with an 0-byte input #81

@mikecat

Description

@mikecat

RawDeflate with FIXED or NONE mode doesn't work well with an 0-byte input. (DYNAMIC looks working)

Using NONE produces 32768 0x00s, which results in an error when inflated.
Using FIXED produces 1-byte output 0x03, but it also results in an error when inflated.

Test code (tested on RunKit + npm: zlibjs with Node 16):

var rawdeflate = require("zlibjs/bin/rawdeflate.min.js");
var rawinflate = require("zlibjs/bin/rawinflate.min.js");

var inputArray = new Uint8Array([]);
console.log(inputArray);

var options = [
	rawdeflate.Zlib.RawDeflate.CompressionType.NONE,
	rawdeflate.Zlib.RawDeflate.CompressionType.FIXED,
	rawdeflate.Zlib.RawDeflate.CompressionType.DYNAMIC
];

for (var i = 0; i < options.length; i++) {
	console.log(options[i]);
	try {
		var option = {
			compressionType: options[i]
		};

		var deflate = new rawdeflate.Zlib.RawDeflate(inputArray, option);
		var compressed = deflate.compress();
		console.log(compressed);

		var inflate = new rawinflate.Zlib.RawInflate(compressed);
		var inflated = inflate.decompress();
		console.log(inflated);
	} catch(e) {
		console.log(e);
	}
}

Reffering rfc1951, I think NONE should produce [0x01, 0x00, 0x00, 0xff, 0xff] and FIXED should produce [0x03, 0x00]. Both of them can be inflated to a 0-byte result.

var rawinflate = require("zlibjs/bin/rawinflate.min.js");

var noneExpected = new Uint8Array([0x01, 0x00, 0x00, 0xff, 0xff]);
var fixedExpected = new Uint8Array([0x03, 0x00]);

var inflateNone = new rawinflate.Zlib.RawInflate(noneExpected);
console.log(inflateNone.decompress());

var inflateFixed = new rawinflate.Zlib.RawInflate(fixedExpected);
console.log(inflateFixed.decompress());

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions