@@ -35,10 +35,10 @@ type SectorList = {
35
35
}
36
36
type CFBFiles = {[n:string]:CFBEntry};
37
37
*/
38
- /* [MS-CFB] v20130118 */
38
+ /* [MS-CFB] v20171201 */
39
39
var CFB = ( function _CFB ( ) {
40
40
var exports /*:CFBModule*/ = /*::(*/ { } /*:: :any)*/ ;
41
- exports . version = '1.0.3 ' ;
41
+ exports . version = '1.0.5 ' ;
42
42
/* [MS-CFB] 2.6.4 */
43
43
function namecmp ( l /*:string*/ , r /*:string*/ ) /*:number*/ {
44
44
var L = l . split ( "/" ) , R = r . split ( "/" ) ;
@@ -62,6 +62,7 @@ function filename(p/*:string*/)/*:string*/ {
62
62
var fs /*:: = require('fs'); */ ;
63
63
function get_fs ( ) { return fs || ( fs = require ( 'fs' ) ) ; }
64
64
function parse ( file /*:RawBytes*/ , options /*:CFBReadOpts*/ ) /*:CFBContainer*/ {
65
+ if ( file . length < 512 ) throw new Error ( "CFB file size " + file . length + " < 512" ) ;
65
66
var mver = 3 ;
66
67
var ssz = 512 ;
67
68
var nmfs = 0 ; // number of mini FAT sectors
@@ -218,7 +219,7 @@ function build_full_paths(FI/*:CFBFileIndex*/, FP/*:Array<string>*/, Paths/*:Arr
218
219
if ( L !== - 1 ) { dad [ L ] = dad [ i ] ; q . push ( L ) ; }
219
220
if ( R !== - 1 ) { dad [ R ] = dad [ i ] ; q . push ( R ) ; }
220
221
}
221
- for ( i = 1 ; i !== pl ; ++ i ) if ( dad [ i ] === i ) {
222
+ for ( i = 1 ; i < pl ; ++ i ) if ( dad [ i ] === i ) {
222
223
if ( R !== - 1 /*NOSTREAM*/ && dad [ R ] !== R ) dad [ i ] = dad [ R ] ;
223
224
else if ( L !== - 1 && dad [ L ] !== L ) dad [ i ] = dad [ L ] ;
224
225
}
@@ -610,7 +611,6 @@ function _write(cfb/*:CFBContainer*/, options/*:CFBWriteOpts*/)/*:RawBytes*/ {
610
611
}
611
612
/* [MS-CFB] 2.6.4 (Unicode 3.0.1 case conversion) */
612
613
function find ( cfb /*:CFBContainer*/ , path /*:string*/ ) /*:?CFBEntry*/ {
613
- //return cfb.find(path);
614
614
var UCFullPaths /*:Array<string>*/ = cfb . FullPaths . map ( function ( x ) { return x . toUpperCase ( ) ; } ) ;
615
615
var UCPaths /*:Array<string>*/ = UCFullPaths . map ( function ( x ) { var y = x . split ( "/" ) ; return y [ y . length - ( x . slice ( - 1 ) == "/" ? 2 : 1 ) ] ; } ) ;
616
616
var k /*:boolean*/ = false ;
@@ -620,10 +620,12 @@ function find(cfb/*:CFBContainer*/, path/*:string*/)/*:?CFBEntry*/ {
620
620
var w /*:number*/ = k === true ? UCFullPaths . indexOf ( UCPath ) : UCPaths . indexOf ( UCPath ) ;
621
621
if ( w !== - 1 ) return cfb . FileIndex [ w ] ;
622
622
623
- UCPath = UCPath . replace ( chr0 , '' ) . replace ( chr1 , '!' ) ;
623
+ var m = ! UCPath . match ( chr1 ) ;
624
+ UCPath = UCPath . replace ( chr0 , '' ) ;
625
+ if ( m ) UCPath = UCPath . replace ( chr1 , '!' ) ;
624
626
for ( w = 0 ; w < UCFullPaths . length ; ++ w ) {
625
- if ( UCFullPaths [ w ] . replace ( chr0 , '' ) . replace ( chr1 , '! ') == UCPath ) return cfb . FileIndex [ w ] ;
626
- if ( UCPaths [ w ] . replace ( chr0 , '' ) . replace ( chr1 , '! ') == UCPath ) return cfb . FileIndex [ w ] ;
627
+ if ( ( m ? UCFullPaths [ w ] . replace ( chr1 , '!' ) : UCFullPaths [ w ] ) . replace ( chr0 , ' ') == UCPath ) return cfb . FileIndex [ w ] ;
628
+ if ( ( m ? UCPaths [ w ] . replace ( chr1 , '!' ) : UCPaths [ w ] ) . replace ( chr0 , ' ') == UCPath ) return cfb . FileIndex [ w ] ;
627
629
}
628
630
return null ;
629
631
}
0 commit comments