stgelem.cxx (046d9d1f) | stgelem.cxx (297a844a) |
---|---|
1/************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance --- 60 unchanged lines hidden (view full) --- 69 << (sal_uInt8) rId.n9 70 << (sal_uInt8) rId.n10 71 << (sal_uInt8) rId.n11; 72} 73 74///////////////////////////// class StgHeader //////////////////////////// 75 76StgHeader::StgHeader() | 1/************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance --- 60 unchanged lines hidden (view full) --- 69 << (sal_uInt8) rId.n9 70 << (sal_uInt8) rId.n10 71 << (sal_uInt8) rId.n11; 72} 73 74///////////////////////////// class StgHeader //////////////////////////// 75 76StgHeader::StgHeader() |
77: nVersion( 0 ) 78, nByteOrder( 0 ) 79, nPageSize( 0 ) 80, nDataPageSize( 0 ) 81, bDirty( 0 ) 82, nFATSize( 0 ) 83, nTOCstrm( 0 ) 84, nReserved( 0 ) 85, nThreshold( 0 ) 86, nDataFAT( 0 ) 87, nDataFATSize( 0 ) 88, nMasterChain( 0 ) 89, nMaster( 0 ) |
|
77{ | 90{ |
78 memset( this, 0, sizeof( StgHeader ) ); | 91 memset( cSignature, 0, sizeof( cSignature ) ); 92 memset( &aClsId, 0, sizeof( ClsId ) ); 93 memset( cReserved, 0, sizeof( cReserved ) ); 94 memset( nMasterFAT, 0, sizeof( nMasterFAT ) ); |
79} 80 81void StgHeader::Init() 82{ | 95} 96 97void StgHeader::Init() 98{ |
83 memset( this, 0, sizeof( StgHeader ) ); | |
84 memcpy( cSignature, cStgSignature, 8 ); | 99 memcpy( cSignature, cStgSignature, 8 ); |
100 memset( &aClsId, 0, sizeof( ClsId ) ); |
|
85 nVersion = 0x0003003B; 86 nByteOrder = 0xFFFE; 87 nPageSize = 9; // 512 bytes 88 nDataPageSize = 6; // 64 bytes | 101 nVersion = 0x0003003B; 102 nByteOrder = 0xFFFE; 103 nPageSize = 9; // 512 bytes 104 nDataPageSize = 6; // 64 bytes |
105 bDirty = 0; 106 memset( cReserved, 0, sizeof( cReserved ) ); 107 nFATSize = 0; 108 nTOCstrm = 0; 109 nReserved = 0; |
|
89 nThreshold = 4096; | 110 nThreshold = 4096; |
111 nDataFAT = 0; |
|
90 nDataFATSize = 0; 91 nMasterChain = STG_EOF; | 112 nDataFATSize = 0; 113 nMasterChain = STG_EOF; |
114 |
|
92 SetTOCStart( STG_EOF ); 93 SetDataFATStart( STG_EOF ); 94 for( short i = 0; i < 109; i++ ) 95 SetFATPage( i, STG_FREE ); 96} 97 98sal_Bool StgHeader::Load( StgIo& rIo ) 99{ | 115 SetTOCStart( STG_EOF ); 116 SetDataFATStart( STG_EOF ); 117 for( short i = 0; i < 109; i++ ) 118 SetFATPage( i, STG_FREE ); 119} 120 121sal_Bool StgHeader::Load( StgIo& rIo ) 122{ |
100 SvStream& r = *rIo.GetStrm(); 101 Load( r ); 102 return rIo.Good(); | 123 sal_Bool bResult = sal_False; 124 if ( rIo.GetStrm() ) 125 { 126 SvStream& r = *rIo.GetStrm(); 127 bResult = Load( r ); 128 bResult = ( bResult && rIo.Good() ); 129 } 130 131 return bResult; |
103} 104 105sal_Bool StgHeader::Load( SvStream& r ) 106{ 107 r.Seek( 0L ); 108 r.Read( cSignature, 8 ); 109 r >> aClsId // 08 Class ID 110 >> nVersion // 1A version number --- 6 unchanged lines hidden (view full) --- 117 >> nReserved // 34 118 >> nThreshold // 38 minimum file size for big data 119 >> nDataFAT // 3C page # of 1st data FAT block 120 >> nDataFATSize // 40 # of data FATpages 121 >> nMasterChain // 44 chain to the next master block 122 >> nMaster; // 48 # of additional master blocks 123 for( short i = 0; i < 109; i++ ) 124 r >> nMasterFAT[ i ]; | 132} 133 134sal_Bool StgHeader::Load( SvStream& r ) 135{ 136 r.Seek( 0L ); 137 r.Read( cSignature, 8 ); 138 r >> aClsId // 08 Class ID 139 >> nVersion // 1A version number --- 6 unchanged lines hidden (view full) --- 146 >> nReserved // 34 147 >> nThreshold // 38 minimum file size for big data 148 >> nDataFAT // 3C page # of 1st data FAT block 149 >> nDataFATSize // 40 # of data FATpages 150 >> nMasterChain // 44 chain to the next master block 151 >> nMaster; // 48 # of additional master blocks 152 for( short i = 0; i < 109; i++ ) 153 r >> nMasterFAT[ i ]; |
125 return r.GetErrorCode() == ERRCODE_NONE; | 154 155 return ( r.GetErrorCode() == ERRCODE_NONE && Check() ); |
126} 127 128sal_Bool StgHeader::Store( StgIo& rIo ) 129{ 130 if( !bDirty ) 131 return sal_True; 132 SvStream& r = *rIo.GetStrm(); 133 r.Seek( 0L ); --- 22 unchanged lines hidden (view full) --- 156 return shift >= 0 && shift < (short)sizeof(short) * 8 - 1; 157} 158 159// Perform thorough checks also on unknown variables 160sal_Bool StgHeader::Check() 161{ 162 return sal_Bool( memcmp( cSignature, cStgSignature, 8 ) == 0 163 && (short) ( nVersion >> 16 ) == 3 ) | 156} 157 158sal_Bool StgHeader::Store( StgIo& rIo ) 159{ 160 if( !bDirty ) 161 return sal_True; 162 SvStream& r = *rIo.GetStrm(); 163 r.Seek( 0L ); --- 22 unchanged lines hidden (view full) --- 186 return shift >= 0 && shift < (short)sizeof(short) * 8 - 1; 187} 188 189// Perform thorough checks also on unknown variables 190sal_Bool StgHeader::Check() 191{ 192 return sal_Bool( memcmp( cSignature, cStgSignature, 8 ) == 0 193 && (short) ( nVersion >> 16 ) == 3 ) |
194 && nPageSize == 9 |
|
164 && lcl_wontoverflow(nPageSize) | 195 && lcl_wontoverflow(nPageSize) |
165 && lcl_wontoverflow(nDataPageSize); | 196 && lcl_wontoverflow(nDataPageSize) 197 && nFATSize > 0 198 && nTOCstrm >= 0 199 && nThreshold > 0 200 && ( nDataFAT == -2 || ( nDataFAT >= 0 && nDataFATSize > 0 ) ) 201 && ( nMasterChain == -2 || ( nMasterChain >=0 && nMaster > 109 ) ) 202 && nMaster >= 0; |
166} 167 168sal_Int32 StgHeader::GetFATPage( short n ) const 169{ 170 if( n >= 0 && n < 109 ) 171 return nMasterFAT[ n ]; 172 else 173 return STG_EOF; --- 72 unchanged lines hidden (view full) --- 246/* 247static void FromUnicode( String& rName ) 248{ 249 rName.Convert( CHARSET_ANSI, ::GetSystemCharSet() ); 250} 251*/ 252sal_Bool StgEntry::Init() 253{ | 203} 204 205sal_Int32 StgHeader::GetFATPage( short n ) const 206{ 207 if( n >= 0 && n < 109 ) 208 return nMasterFAT[ n ]; 209 else 210 return STG_EOF; --- 72 unchanged lines hidden (view full) --- 283/* 284static void FromUnicode( String& rName ) 285{ 286 rName.Convert( CHARSET_ANSI, ::GetSystemCharSet() ); 287} 288*/ 289sal_Bool StgEntry::Init() 290{ |
254 memset( this, 0, sizeof (StgEntry) - sizeof( String ) ); | 291 memset( nName, 0, sizeof( nName ) ); 292 nNameLen = 0; 293 cType = 0; 294 cFlags = 0; 295 nLeft = 0; 296 nRight = 0; 297 nChild = 0; 298 memset( &aClsId, 0, sizeof( aClsId ) ); 299 nFlags = 0; 300 nMtime[0] = 0; nMtime[1] = 0; 301 nAtime[0] = 0; nAtime[1] = 0; 302 nPage1 = 0; 303 nSize = 0; 304 nUnknown = 0; 305 |
255 SetLeaf( STG_LEFT, STG_FREE ); 256 SetLeaf( STG_RIGHT, STG_FREE ); 257 SetLeaf( STG_CHILD, STG_FREE ); 258 SetLeaf( STG_DATA, STG_EOF ); 259 return sal_True; 260} 261 262static String ToUpperUnicode( const String & rStr ) --- 90 unchanged lines hidden (view full) --- 353 nRes = r.aName.CompareTo( aName ); 354 return (short)nRes; 355 //return aName.CompareTo( r.aName ); 356} 357 358// These load/store operations are a bit more complicated, 359// since they have to copy their contents into a packed structure. 360 | 306 SetLeaf( STG_LEFT, STG_FREE ); 307 SetLeaf( STG_RIGHT, STG_FREE ); 308 SetLeaf( STG_CHILD, STG_FREE ); 309 SetLeaf( STG_DATA, STG_EOF ); 310 return sal_True; 311} 312 313static String ToUpperUnicode( const String & rStr ) --- 90 unchanged lines hidden (view full) --- 404 nRes = r.aName.CompareTo( aName ); 405 return (short)nRes; 406 //return aName.CompareTo( r.aName ); 407} 408 409// These load/store operations are a bit more complicated, 410// since they have to copy their contents into a packed structure. 411 |
361sal_Bool StgEntry::Load( const void* pFrom ) | 412sal_Bool StgEntry::Load( const void* pFrom, sal_uInt32 nBufSize ) |
362{ | 413{ |
363 SvMemoryStream r( (sal_Char*) pFrom, 128, STREAM_READ ); | 414 if ( nBufSize < 128 ) 415 return sal_False; 416 417 SvMemoryStream r( (sal_Char*) pFrom, nBufSize, STREAM_READ ); |
364 for( short i = 0; i < 32; i++ ) 365 r >> nName[ i ]; // 00 name as WCHAR 366 r >> nNameLen // 40 size of name in bytes including 00H 367 >> cType // 42 entry type 368 >> cFlags // 43 0 or 1 (tree balance?) 369 >> nLeft // 44 left node entry 370 >> nRight // 48 right node entry 371 >> nChild // 4C 1st child entry if storage --- 5 unchanged lines hidden (view full) --- 377 >> nAtime[ 1 ] // 6C creation and access time 378 >> nPage1 // 74 starting block (either direct or translated) 379 >> nSize // 78 file size 380 >> nUnknown; // 7C unknown 381 382 sal_uInt16 n = nNameLen; 383 if( n ) 384 n = ( n >> 1 ) - 1; | 418 for( short i = 0; i < 32; i++ ) 419 r >> nName[ i ]; // 00 name as WCHAR 420 r >> nNameLen // 40 size of name in bytes including 00H 421 >> cType // 42 entry type 422 >> cFlags // 43 0 or 1 (tree balance?) 423 >> nLeft // 44 left node entry 424 >> nRight // 48 right node entry 425 >> nChild // 4C 1st child entry if storage --- 5 unchanged lines hidden (view full) --- 431 >> nAtime[ 1 ] // 6C creation and access time 432 >> nPage1 // 74 starting block (either direct or translated) 433 >> nSize // 78 file size 434 >> nUnknown; // 7C unknown 435 436 sal_uInt16 n = nNameLen; 437 if( n ) 438 n = ( n >> 1 ) - 1; |
385 if( n > 31 || (nSize < 0 && cType != STG_STORAGE) ) | 439 if( n > 31 || (nSize < 0 && cType != STG_STORAGE) || ( nPage1 < 0 && nPage1 != -2 ) ) |
386 { 387 // the size makes no sence for the substorage 388 // TODO/LATER: actually the size should be an unsigned value, but in this case it would mean a stream of more than 2Gb 389 return sal_False; 390 } 391 392 aName = String( nName, n ); 393 // I don't know the locale, so en_US is hopefully fine --- 28 unchanged lines hidden --- | 440 { 441 // the size makes no sence for the substorage 442 // TODO/LATER: actually the size should be an unsigned value, but in this case it would mean a stream of more than 2Gb 443 return sal_False; 444 } 445 446 aName = String( nName, n ); 447 // I don't know the locale, so en_US is hopefully fine --- 28 unchanged lines hidden --- |