~ubuntu-branches/ubuntu/precise/p7zip/precise-updates

« back to all changes in this revision

Viewing changes to CPP/7zip/Archive/Chm/ChmIn.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mohammed Adnène Trojette
  • Date: 2009-02-14 20:12:27 UTC
  • mfrom: (1.1.11 upstream) (2.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090214201227-go63qxm9ozfdma60
Tags: 4.65~dfsg.1-1
* New upstream release.
* Remove wx2.8 Build-Depends added by mistakes (7zG is not yet
  intended to be built).
* Use dh_clean without -k.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
// define CHM_LOW, if you want to see low level items
18
18
// #define CHM_LOW
19
19
 
20
 
static const GUID kChmLzxGuid = 
 
20
static const GUID kChmLzxGuid =
21
21
  { 0x7FC28940, 0x9D31, 0x11D0, 0x9B, 0x27, 0x00, 0xA0, 0xC9, 0x1E, 0x9C, 0x7C };
22
 
static const GUID kHelp2LzxGuid = 
 
22
static const GUID kHelp2LzxGuid =
23
23
  { 0x0A9007C6, 0x4076, 0x11D3, 0x87, 0x89, 0x00, 0x00, 0xF8, 0x10, 0x57, 0x54 };
24
 
static const GUID kDesGuid = 
 
24
static const GUID kDesGuid =
25
25
  { 0x67F6E4A2, 0x60BF, 0x11D3, 0x85, 0x40, 0x00, 0xC0, 0x4F, 0x58, 0xC3, 0xCF };
26
26
 
27
27
static bool AreGuidsEqual(REFGUID g1, REFGUID g2)
28
 
29
 
  if (g1.Data1 != g2.Data1 || 
 
28
{
 
29
  if (g1.Data1 != g2.Data1 ||
30
30
      g1.Data2 != g2.Data2 ||
31
31
      g1.Data3 != g2.Data3)
32
32
    return false;
60
60
}
61
61
 
62
62
AString CMethodInfo::GetGuidString() const
63
 
 
63
{
64
64
  AString s;
65
65
  s += '{';
66
66
  PrintUInt32(Guid.Data1, s);
278
278
  if (unknown1 != 0 && unknown1 != 1) // it's 0 in one .sll file
279
279
    return S_FALSE;
280
280
  /* UInt32 timeStamp = */ ReadUInt32();
281
 
      // Considered as a big-endian DWORD, it appears to contain seconds (MSB) and 
282
 
      // fractional seconds (second byte). 
283
 
      // The third and fourth bytes may contain even more fractional bits.  
 
281
      // Considered as a big-endian DWORD, it appears to contain seconds (MSB) and
 
282
      // fractional seconds (second byte).
 
283
      // The third and fourth bytes may contain even more fractional bits.
284
284
      // The 4 least significant bits in the last byte are constant.
285
285
  /* UInt32 lang = */ ReadUInt32();
286
286
  GUID g;
326
326
  if (dirChunkSize < 32)
327
327
    return S_FALSE;
328
328
  /* UInt32 density = */ ReadUInt32(); //  "Density" of quickref section, usually 2.
329
 
  /* UInt32 depth = */ ReadUInt32(); //  Depth of the index tree: 1 there is no index, 
 
329
  /* UInt32 depth = */ ReadUInt32(); //  Depth of the index tree: 1 there is no index,
330
330
                               // 2 if there is one level of PMGI chunks.
331
331
 
332
332
  /* UInt32 chunkNumber = */ ReadUInt32(); //  Chunk number of root index chunk, -1 if there is none
333
 
                                     // (though at least one file has 0 despite there being no 
334
 
                                     // index chunk, probably a bug.) 
 
333
                                     // (though at least one file has 0 despite there being no
 
334
                                     // index chunk, probably a bug.)
335
335
  /* UInt32 firstPmglChunkNumber = */ ReadUInt32(); // Chunk number of first PMGL (listing) chunk
336
336
  /* UInt32 lastPmglChunkNumber = */ ReadUInt32();  // Chunk number of last PMGL (listing) chunk
337
337
  ReadUInt32(); // -1 (unknown)
348
348
    UInt64 chunkPos = _inBuffer.GetProcessedSize();
349
349
    if (ReadUInt32() == NHeader::kPmglSignature)
350
350
    {
351
 
      // The quickref area is written backwards from the end of the chunk. 
352
 
      // One quickref entry exists for every n entries in the file, where n 
353
 
      // is calculated as 1 + (1 << quickref density). So for density = 2, n = 5. 
 
351
      // The quickref area is written backwards from the end of the chunk.
 
352
      // One quickref entry exists for every n entries in the file, where n
 
353
      // is calculated as 1 + (1 << quickref density). So for density = 2, n = 5.
354
354
 
355
 
      UInt32 quickrefLength = ReadUInt32(); // Length of free space and/or quickref area at end of directory chunk 
 
355
      UInt32 quickrefLength = ReadUInt32(); // Length of free space and/or quickref area at end of directory chunk
356
356
      if (quickrefLength > dirChunkSize || quickrefLength < 2)
357
357
        return S_FALSE;
358
358
      ReadUInt32(); // Always 0
393
393
  if (numHeaderSections != kNumHeaderSectionsMax)
394
394
    return S_FALSE;
395
395
  ReadUInt32(); // Length of post-header table
396
 
  GUID g; 
 
396
  GUID g;
397
397
  ReadGUID(g);  // {0A9007C1-4076-11D3-8789-0000F8105754}
398
398
 
399
 
  // header section table 
 
399
  // header section table
400
400
  UInt64 sectionOffsets[kNumHeaderSectionsMax];
401
401
  UInt64 sectionSizes[kNumHeaderSectionsMax];
402
402
  UInt32 i;
434
434
  ReadUInt64(); // Number of directory index entries (same as number of AOLL
435
435
               // chunks in main directory)
436
436
  
437
 
  // (The obvious guess for the following two fields, which recur in a number 
438
 
  // of places, is they are maximum sizes for the directory and directory index. 
439
 
  // However, I have seen no direct evidence that this is the case.) 
 
437
  // (The obvious guess for the following two fields, which recur in a number
 
438
  // of places, is they are maximum sizes for the directory and directory index.
 
439
  // However, I have seen no direct evidence that this is the case.)
440
440
 
441
441
  ReadUInt32(); // $100000 (Same as field following chunk size in directory)
442
442
  ReadUInt32(); // $20000 (Same as field following chunk size in directory index)
480
480
      if (unknown != 0 && unknown != 1) // = 0 for some HxW files, 1 in other cases;
481
481
        return S_FALSE;
482
482
      database.ContentOffset = _startPosition + ReadUInt64();
483
 
      /* UInt32 timeStamp = */ ReadUInt32(); 
484
 
          // A timestamp of some sort.  
 
483
      /* UInt32 timeStamp = */ ReadUInt32();
 
484
          // A timestamp of some sort.
485
485
          // Considered as a big-endian DWORD, it appears to contain
486
486
          // seconds (MSB) and fractional seconds (second byte).
487
487
          // The third and fourth bytes may contain even more fractional
527
527
      UInt32 quickrefLength = ReadUInt32(); // Length of quickref area at end of directory chunk
528
528
      if (quickrefLength > dirChunkSize || quickrefLength < 2)
529
529
        return S_FALSE;
530
 
      ReadUInt64(); // Directory chunk number 
 
530
      ReadUInt64(); // Directory chunk number
531
531
            // This must match physical position in file, that is
532
532
            // the chunk size times the chunk number must be the
533
533
            // offset from the end of the directory header.
625
625
  const CObjectVector<CItem> &items = *(const CObjectVector<CItem> *)param;
626
626
  const CItem &item1 = items[*p1];
627
627
  const CItem &item2 = items[*p2];
628
 
  bool isDir1 = item1.IsDirectory();
629
 
  bool isDir2 = item2.IsDirectory();
 
628
  bool isDir1 = item1.IsDir();
 
629
  bool isDir2 = item2.IsDir();
630
630
  if (isDir1 && !isDir2)
631
631
    return -1;
632
632
  if (isDir2)
663
663
  for(int i = 0; i < Indices.Size(); i++)
664
664
  {
665
665
    const CItem &item = Items[Indices[i]];
666
 
    if (item.Section == 0 || item.IsDirectory())
 
666
    if (item.Section == 0 || item.IsDir())
667
667
      continue;
668
668
    if (item.Section != prevSection)
669
669
    {
718
718
    AString transformPrefix = sectionPrefix + kTransform;
719
719
    if (database.Help2Format)
720
720
    {
721
 
      // Transform List 
 
721
      // Transform List
722
722
      RINOK(DecompressStream(inStream, database, transformPrefix + kTransformList));
723
723
      if ((_chunkSize & 0xF) != 0)
724
724
        return S_FALSE;
760
760
          li.WindowSize = ReadUInt32();
761
761
          li.CacheSize = ReadUInt32();
762
762
          if (
763
 
              li.ResetInterval != 1 && 
764
 
              li.ResetInterval != 2 && 
765
 
              li.ResetInterval != 4 && 
766
 
              li.ResetInterval != 8 && 
767
 
              li.ResetInterval != 16 && 
768
 
              li.ResetInterval != 32 && 
 
763
              li.ResetInterval != 1 &&
 
764
              li.ResetInterval != 2 &&
 
765
              li.ResetInterval != 4 &&
 
766
              li.ResetInterval != 8 &&
 
767
              li.ResetInterval != 16 &&
 
768
              li.ResetInterval != 32 &&
769
769
              li.ResetInterval != 64)
770
770
            return S_FALSE;
771
771
          if (
772
 
              li.WindowSize != 1 && 
773
 
              li.WindowSize != 2 && 
774
 
              li.WindowSize != 4 && 
775
 
              li.WindowSize != 8 && 
776
 
              li.WindowSize != 16 && 
777
 
              li.WindowSize != 32 && 
 
772
              li.WindowSize != 1 &&
 
773
              li.WindowSize != 2 &&
 
774
              li.WindowSize != 4 &&
 
775
              li.WindowSize != 8 &&
 
776
              li.WindowSize != 16 &&
 
777
              li.WindowSize != 32 &&
778
778
              li.WindowSize != 64)
779
779
            return S_FALSE;
780
780
          numDWORDS -= 5;
803
803
      if (method.IsLzx())
804
804
      {
805
805
        // ResetTable;
806
 
        RINOK(DecompressStream(inStream, database, transformPrefix + 
 
806
        RINOK(DecompressStream(inStream, database, transformPrefix +
807
807
            method.GetGuidString() + kResetTable));
808
808
        CResetTable &rt = method.LzxInfo.ResetTable;
809
809
        if (_chunkSize < 4)
845
845
  return database.Check() ? S_OK : S_FALSE;
846
846
}
847
847
 
848
 
HRESULT CInArchive::Open2(IInStream *inStream, 
 
848
HRESULT CInArchive::Open2(IInStream *inStream,
849
849
    const UInt64 *searchHeaderSizeLimit,
850
850
    CFilesDatabase &database)
851
851
{
864
864
    const int kSignatureSize = 8;
865
865
    UInt64 hxsSignature = NHeader::GetHxsSignature();
866
866
    UInt64 chmSignature = ((UInt64)chmVersion << 32)| NHeader::kItsfSignature;
 
867
    UInt64 limit = 1 << 18;
 
868
    if (searchHeaderSizeLimit)
 
869
      if (limit > *searchHeaderSizeLimit)
 
870
        limit = *searchHeaderSizeLimit;
 
871
 
867
872
    for (;;)
868
873
    {
869
874
      Byte b;
880
885
          database.Help2Format = true;
881
886
          break;
882
887
        }
883
 
        if (searchHeaderSizeLimit != NULL)
884
 
          if (_inBuffer.GetProcessedSize() > (*searchHeaderSizeLimit))
885
 
            return S_FALSE;
 
888
        if (_inBuffer.GetProcessedSize() > limit)
 
889
          return S_FALSE;
886
890
      }
887
891
    }
888
892
    _startPosition += _inBuffer.GetProcessedSize() - kSignatureSize;
919
923
  return S_OK;
920
924
}
921
925
 
922
 
HRESULT CInArchive::Open(IInStream *inStream, 
 
926
HRESULT CInArchive::Open(IInStream *inStream,
923
927
    const UInt64 *searchHeaderSizeLimit,
924
928
    CFilesDatabase &database)
925
929
{