kesla / node-snappy

DEPRECATED - please use https://github.com/Brooooooklyn/snappy. Nodejs bindings to Google's Snappy compression library
Other
481 stars 52 forks source link

Invalid input when processing iWork files? #68

Closed gCurtisCT closed 9 years ago

gCurtisCT commented 9 years ago

Apparently, iWork IWA files don't totally adhere to snappy standards https://github.com/obriensp/iWorkFileFormat/blob/master/Docs/index.md#iwa

IWA files are stored in Snappy's framing format, though they do not adhere rigorously to the spec. In particular, they do not include the required Stream Identifier chunk, and compressed chunks do not> include a CRC-32C checksum.

The stream is composed of contiguous chunks prefixed by a 4 byte header. The first byte indicates the chunk type, which in practice is always 0 for iWork, indicating a Snappy compressed chunk. The next three bytes are interpreted as a 24-bit little-endian integer indicating the length of the chunk. The 4 byte header is not included in the chunk length.

When I try to uncompress an .iwa file, like so:

var fs = require('fs');
var unzip = require('unzip');
var snappy = require('snappy');

fs.createReadStream('Keynote.key').pipe(unzip.Extract({path:'./unzipped'}))
.on('close',function(){
    var file = fs.readFileSync('./unzipped/Index/Slide1.iwa');
    snappy.uncompress(file,function(err,original){
        console.log('err is',err);
        console.log('original is',original);
    });
});

I get [Error: Invalid input]. I'm assuming it's checking what the iWork does not adhere to?

Or if there's something wrong with my code, please let me know.

The file was made from a Keynote v6.5.3

Here is the .iwa file as opened by a text editor, because I couldn't think of a better way to send it.

00a8 0300 a30f f04c 2308 c415 121e 0805
1203 0100 0518 8501 2a12 f517 f417 f317
f617 f717 d419 8619 b115 b117 0a03 08b1
1722 2a12 2830 0042 240a 0a54 7261 6e73
6974 696f 6e12 046e 6f6e 6519 0000 0000
0000 f03f 2905 0834 00e0 3f2a 0308 f317
3203 08f4 173a 010a 003a 0d0a 9886 193a
0308 d419 8a01 0308 b115 9801 01a2 0103
08f5 17da 0103 08f7 17a2 0203 08f6 17c0
0200 d202 0133 0106 00f4 0506 0486 1901
0c28 d419 1508 f517 1210 0807 1205 a980
bc01 2a04 c318 a816 0ab7 010a af01 0a3e
0a1f 0a0a 0d00 c0ff 4315 0000 3644 120a
0d01 8b00 1501 0508 1800 2501 076c 1203
08c4 151a 1208 0410 0218 0125 0000 4041
2d00 0000 3f30 0028 0038 011d 24a8 161a
6808 0010 002a 622e 3d00 141a 540a 0e08
012e 1200 0c0a 0e08 0205 1004 c842 055f
3610 0004 c842 1510 0000 017f 14c8 420a
0208 053e 4400 3c12 0308 c318 1001 1708
c318 1212 08d1 0f09 d35c 4c2a 06ec 15ff
18c2 1612 0308 cf15 1a03 efbf bc2a 090a
0708 012f 14c2 1632 080a 0601 a008 1800
3a11 1508 ec15 4a11 0b10 ff18 5001 7215
2204 c201 150b 1c0f 08ff 1812 0a08 fb0d
642c 080a 040a 0010 0010 0015 08f4 3a4e
0108 c418 dd3a 4e01 09e3 04c6 4305 ef20
4e44 1500 00b2 4218 0392 4e01 00dd 364e
010d 3d6a 4e01 0522 0000 394e 0510 00b2
3a4e 0104 b242 5a4e 0124 c418 1003 1508
c418 1210 3d4e 1004 ec15 f915 2d4c 0868
6579 354c 04f9 1552 4c01 2e41 0100 9a29
410c 1202 656e 3d4c 0815 08f3 3a34 010c
c218 ec17 3682 0229 3400 013d 3404 8243
9a34 0104 ec17 3282 0225 0208 8243 1a66
8202 0522 3e34 0104 8243 3682 0204 8243
5a34 0118 c218 1002 1508 c22e 3401 1456
2a04 ec15 f72d 342c 0d41 6e64 2049 2073
6179 2048 3d3e 00f7 de3e 0120 0f08 f617
120a 08e7 1749 ee1c 0012 08f7 1712 0d08
4d99 3005 2a02 c518 0a03 08c5 1815 08c5
2e94 0020 3e2a 04a9 17e2 1608 0425 ca35
c504 e216 4ac5 0104 a917 2ec5 013d ba1c
1608 d419 1211 08db 0d6d 1cb7 012a 04df
15d5 199d 3a18 00f6 4315 00c0 0ace 3a04
04df 1532 b801 65f8 0000 fe3a 0466 3a04
14d5 1915 08d5 195d ea00 5b21 b604 ce19
2520 4c1a 1263 616e 2079 6f75 2072 6561
6420 7468 6973 3f35 3404 ce19 4a34 0100
ec8a f902 0816 0886 463f 0100 8732 3f01
0000 811f 00f6 49f7 2d02 9a79 05fe 3f01
ba3f 0110 8719 1608 8701 ceb1 7704 9a01
2140 00fc 4df6 6c1c 5768 6174 2061 2077
6f6e 6465 7266 756c 2074 696d 6520 6f66
2064 6199 4300 fcb2 0503 f03f a201 320a
0208 000a 2808 0712 2437 3633 4133 4236
352d 3136 3341 2d34 4441 372d 3935 3534
2d42 3537 4544 4434 4142 3931 420a 0208
10c2 0108 0a06 0800 1000 1800
kesla commented 9 years ago

IWA files are stored in Snappy's framing format means that you should be able to use https://www.npmjs.com/package/snappy-stream to decompress - but if they're not following the spec it'll be a bit of a challenge...

gCurtisCT commented 9 years ago

Yeah, snappy-stream gives me Error: malformed input: must begin with an identifier, which is what the quote says is missing.

kesla commented 9 years ago

@gCurtisCT sorry I can't help you with this. snappy-stream follow the spec, but this format doesn't. Maybe it's possible to fork snappy-stream and addap the uncompression to the way it's formatted in this file format? IDK.