🚑 Fix reading of local file header

This commit is contained in:
C-3PO 2018-07-05 02:33:21 +02:00
parent 520f9c2e39
commit 4f0adf8931
Signed by: c3po
GPG key ID: 62993C4BB4D86F24
2 changed files with 7 additions and 7 deletions

View file

@ -2,7 +2,7 @@
"name": "patcher",
"main": "dist/index.js",
"scripts": {
"start": "rm -rf dist && tsc && node dist/index.js",
"start": "rm -rf dist && tsc",
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {

View file

@ -11,18 +11,18 @@ import streamSetMaxLength from './streams/streamSetMaxLength';
* and must transparently span across multiple disks if necessary.
*/
export default function extractFileStream(file: ISsnFileEntry, inputStream: stream.Readable): stream.Readable {
const headerBuffer: Buffer = inputStream.read(30);
const localFileHeader = new DataView(headerBuffer.buffer);
const localFileHeader: Buffer = inputStream.read(30);
//Local file header signature
if (localFileHeader.getUint32(0, true) !== 0x04034B50) {
throw new Error('Local file header had wrong magic');
const magic = localFileHeader.readUInt32LE(0);
if (magic !== 0x04034B50) {
throw new Error(`Local file header had wrong magic; expected 0x04034B50 but got 0x${magic.toString(16).padStart(8, '0')}`);
}
//All fields in the local file header are copies of the central file header, so we can skip them.
//FIXME: Maybe we should actually read these fields to verify that they are identical?
//skip 22 bytes
const localFilenameSize = localFileHeader.getUint16(26, true);
const localExtraSize = localFileHeader.getUint16(28, true);
const localFilenameSize = localFileHeader.readUInt16LE(26);
const localExtraSize = localFileHeader.readUInt16LE(28);
//skip local file name and extra field
inputStream.read(localFilenameSize + localExtraSize);