Merge branch 'n1073645-master'

This commit is contained in:
n1474335 2019-11-08 13:49:51 +00:00
commit 5e6f3cc5b4

View File

@ -2450,31 +2450,34 @@ export function extractJPEG(bytes, offset) {
export function extractGIF(bytes, offset) { export function extractGIF(bytes, offset) {
const stream = new Stream(bytes.slice(offset)); const stream = new Stream(bytes.slice(offset));
//Move to application extension block. // Move to application extension block.
stream.continueUntil([0x21, 0xff]); stream.continueUntil([0x21, 0xff]);
//Move to Graphic Control Extension for frame #1. // Move to Graphic Control Extension for frame #1.
stream.continueUntil([0x21, 0xf9]); stream.continueUntil([0x21, 0xf9]);
stream.moveForwardsBy(2);
while (stream.hasMore()) { while (stream.hasMore()) {
// Move to Image descriptor.
stream.moveForwardsBy(stream.readInt(1) + 1);
//Move to Image descriptor. // Move past Image descriptor to the image data.
stream.continueUntil(0x2c);
//Move past Image descriptor to the image data.
stream.moveForwardsBy(11); stream.moveForwardsBy(11);
//Loop until next Graphic Control Extension. // Loop until next Graphic Control Extension.
while (stream.getBytes(2) !== [0x21, 0xf9]) { while (stream.getBytes(2) !== [0x21, 0xf9]) {
stream.moveBackwardsBy(2); stream.moveBackwardsBy(2);
stream.moveForwardsBy(stream.getBytes(1)[0]); stream.moveForwardsBy(stream.readInt(1));
if (!stream.getBytes(1)[0]) if (!stream.readInt(1))
break; break;
stream.moveBackwardsBy(1); stream.moveBackwardsBy(1);
} }
//When the end of the file is [0x00, 0x3b], end.
if (stream.getBytes(1)[0] === 0x3b) // When the end of the file is [0x00, 0x3b], end.
if (stream.readInt(1) === 0x3b)
break; break;
stream.moveBackwardsBy(1);
stream.moveForwardsBy(1);
} }
return stream.carve(); return stream.carve();
} }
@ -2818,37 +2821,38 @@ export function extractGZIP(bytes, offset) {
/** /**
* BZIP2 extractor.
*
* @param {Uint8Array} bytes * @param {Uint8Array} bytes
* @param {Number} offset * @param {Number} offset
* @returns {Uint8Array} * @returns {Uint8Array}
*/ */
export function extractBZIP2(bytes, offset){ export function extractBZIP2(bytes, offset) {
const stream = new Stream(bytes.slice(offset)); const stream = new Stream(bytes.slice(offset));
//The EOFs shifted between all possible combinations. // The EOFs shifted between all possible combinations.
var lookingfor = [ const lookingfor = [
[0x77, 0x24, 0x53, 0x85, 0x09], [0x77, 0x24, 0x53, 0x85, 0x09],
[0xee, 0x48, 0xa7, 0x0a, 0x12], [0xee, 0x48, 0xa7, 0x0a, 0x12],
[0xdc, 0x91, 0x4e, 0x14, 0x24], [0xdc, 0x91, 0x4e, 0x14, 0x24],
[0xb9, 0x22, 0x9c, 0x28, 0x48], [0xb9, 0x22, 0x9c, 0x28, 0x48],
[0x72, 0x45, 0x38, 0x50, 0x90], [0x72, 0x45, 0x38, 0x50, 0x90],
[0xbb, 0x92, 0x29, 0xc2, 0x84], [0xbb, 0x92, 0x29, 0xc2, 0x84],
[0x5d, 0xc9, 0x14, 0xe1, 0x42], [0x5d, 0xc9, 0x14, 0xe1, 0x42],
[0x2e, 0xe4, 0x8a, 0x70, 0xa1], [0x2e, 0xe4, 0x8a, 0x70, 0xa1],
[0x17, 0x72, 0x45, 0x38, 0x50]]; [0x17, 0x72, 0x45, 0x38, 0x50]
];
for(let i = 0; i < 9; i++){ for (let i = 0; i < lookingfor.length; i++) {
// Continue until an EOF.
//Continue until an EOF.
stream.continueUntil(lookingfor[i]); stream.continueUntil(lookingfor[i]);
if(stream.getBytes(5).join("") == lookingfor[i].join("")) if (stream.getBytes(5).join("") === lookingfor[i].join(""))
break; break;
//Jump back to the start if invalid EOF. // Jump back to the start if invalid EOF.
stream.moveTo(0); stream.moveTo(0);
} }
stream.moveForwardsBy(4); stream.moveForwardsBy(4);
return stream.carve(); return stream.carve();
} }