optimize zlib inflate, the old code would get stuck on malformed swfs

This commit is contained in:
BiFi2000 2021-05-20 17:53:41 +00:00
parent 32435a3c84
commit 7ce2438ea5

View File

@ -335,27 +335,9 @@ function uncompress(swf, next) {
return readSWFBuff(new SWFBuffer(uncompressed_buff), swf); return readSWFBuff(new SWFBuffer(uncompressed_buff), swf);
} }
const newBuffer = swf.slice(4); zlib.inflate(compressed_buff, function(err, buf) {
const uncompressedLength = newBuffer.readUInt32LE(); readSWFBuff(new SWFBuffer(buf), swf, next);
const chunks = []; });
let readLength = 0;
var decompressStream = zlib.createInflate()
.on('data', function (chunk) {
readLength += chunk.length;
chunks.push(chunk);
if (uncompressedLength - 8 === readLength) {
decompressStream.close();
}
//decompressStream.pause();
}).on('error', function(err) {
console.log(err);
//next(err);
}).on('close', function() {
readSWFBuff(new SWFBuffer( Buffer.concat(chunks) ), swf, next);
});
decompressStream.write(compressed_buff);
break; break;
case 0x46 : // uncompressed case 0x46 : // uncompressed
return readSWFBuff(new SWFBuffer( swf ), swf, next); return readSWFBuff(new SWFBuffer( swf ), swf, next);