Merge branch 'BiFi2000-master-patch-27063' into 'master'

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

See merge request nitro/nitro-converter!4
This commit is contained in:
Bill 2021-08-06 06:05:42 +00:00
commit 450d306cc8

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);