Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mikecat opened this issue Nov 8, 2021 · 0 comments

Comments

@mikecat
Copy link

mikecat commented Nov 8, 2021

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());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant