~ubuntu-branches/ubuntu/quantal/unrar-nonfree/quantal

« back to all changes in this revision

Viewing changes to unpack.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Meredith
  • Date: 2009-06-06 17:46:05 UTC
  • mto: (1.1.11 upstream) (5.1.5 sid)
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20090606174605-825ysfkrhw7wkc9e
ImportĀ upstreamĀ versionĀ 3.9.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
263
263
          if (Failed)
264
264
            break;
265
265
 
266
 
#ifdef _MSC_VER
267
 
  // avoid a warning about uninitialized 'Length' variable
268
 
  #pragma warning( disable : 4701 )
269
 
#endif
270
266
          CopyString(Length+32,Distance+2);
271
267
          continue;
272
268
        }
415
411
  else
416
412
  {
417
413
    NewFile=true;
418
 
    NewTable=(BitField & 0x4000);
 
414
    NewTable=(BitField & 0x4000)!=0;
419
415
    addbits(2);
420
416
  }
421
417
  TablesRead=!NewTable;
442
438
  Array<byte> VMCode(Length);
443
439
  for (int I=0;I<Length;I++)
444
440
  {
 
441
    // Try to read the new buffer if only one byte is left.
 
442
    // But if we read all bytes except the last, one byte is enough.
445
443
    if (InAddr>=ReadTop-1 && !UnpReadBuf() && I<Length-1)
446
444
      return(false);
447
445
    VMCode[I]=getbits()>>8;
522
520
 
523
521
    Filters.Add(1);
524
522
    Filters[Filters.Size()-1]=Filter=new UnpackFilter;
525
 
    StackFilter->ParentFilter=Filters.Size()-1;
 
523
    StackFilter->ParentFilter=(uint)(Filters.Size()-1);
526
524
    OldFilterLengths.Add(1);
527
525
    Filter->ExecCount=0;
528
526
  }
534
532
  }
535
533
 
536
534
  int EmptyCount=0;
537
 
  for (int I=0;I<PrgStack.Size();I++)
 
535
  for (uint I=0;I<PrgStack.Size();I++)
538
536
  {
539
537
    PrgStack[I-EmptyCount]=PrgStack[I];
540
538
    if (PrgStack[I]==NULL)
547
545
    PrgStack.Add(1);
548
546
    EmptyCount=1;
549
547
  }
550
 
  int StackPos=PrgStack.Size()-EmptyCount;
 
548
  int StackPos=(int)(PrgStack.Size()-EmptyCount);
551
549
  PrgStack[StackPos]=StackFilter;
552
550
  StackFilter->ExecCount=Filter->ExecCount;
553
551
 
585
583
    if (VMCodeSize>=0x10000 || VMCodeSize==0)
586
584
      return(false);
587
585
    Array<byte> VMCode(VMCodeSize);
588
 
    for (int I=0;I<VMCodeSize;I++)
 
586
    for (uint I=0;I<VMCodeSize;I++)
589
587
    {
590
588
      if (Inp.Overflow(3))
591
589
        return(false);
597
595
  StackFilter->Prg.AltCmd=&Filter->Prg.Cmd[0];
598
596
  StackFilter->Prg.CmdCount=Filter->Prg.CmdCount;
599
597
 
600
 
  int StaticDataSize=Filter->Prg.StaticData.Size();
 
598
  size_t StaticDataSize=Filter->Prg.StaticData.Size();
601
599
  if (StaticDataSize>0 && StaticDataSize<VM_GLOBALMEMSIZE)
602
600
  {
603
601
    // read statically defined data contained in DB commands
625
623
    uint DataSize=RarVM::ReadData(Inp);
626
624
    if (DataSize>VM_GLOBALMEMSIZE-VM_FIXEDGLOBALSIZE)
627
625
      return(false);
628
 
    unsigned int CurSize=StackFilter->Prg.GlobalData.Size();
 
626
    size_t CurSize=StackFilter->Prg.GlobalData.Size();
629
627
    if (CurSize<DataSize+VM_FIXEDGLOBALSIZE)
630
628
      StackFilter->Prg.GlobalData.Add(DataSize+VM_FIXEDGLOBALSIZE-CurSize);
631
629
    byte *GlobalData=&StackFilter->Prg.GlobalData[VM_FIXEDGLOBALSIZE];
632
 
    for (int I=0;I<DataSize;I++)
 
630
    for (uint I=0;I<DataSize;I++)
633
631
    {
634
632
      if (Inp.Overflow(3))
635
633
        return(false);
643
641
 
644
642
bool Unpack::UnpReadBuf()
645
643
{
646
 
  int DataSize=ReadTop-InAddr;
 
644
  int DataSize=ReadTop-InAddr; // Data left to process.
647
645
  if (DataSize<0)
648
646
    return(false);
649
647
  if (InAddr>BitInput::MAX_SIZE/2)
650
648
  {
 
649
    // If we already processed more than half of buffer, let's move
 
650
    // remaining data into beginning to free more space for new data.
651
651
    if (DataSize>0)
652
652
      memmove(InBuf,InBuf+InAddr,DataSize);
653
653
    InAddr=0;
667
667
{
668
668
  unsigned int WrittenBorder=WrPtr;
669
669
  unsigned int WriteSize=(UnpPtr-WrittenBorder)&MAXWINMASK;
670
 
  for (int I=0;I<PrgStack.Size();I++)
 
670
  for (size_t I=0;I<PrgStack.Size();I++)
671
671
  {
672
672
    UnpackFilter *flt=PrgStack[I];
673
673
    if (flt==NULL)
773
773
      }
774
774
      else
775
775
      {
776
 
        for (int J=I;J<PrgStack.Size();J++)
 
776
        for (size_t J=I;J<PrgStack.Size();J++)
777
777
        {
778
778
          UnpackFilter *flt=PrgStack[J];
779
779
          if (flt!=NULL && flt->NextWindow)
794
794
{
795
795
  if (Prg->GlobalData.Size()>0)
796
796
  {
797
 
    Prg->InitR[6]=int64to32(WrittenFileSize);
798
 
    VM.SetLowEndianValue((uint *)&Prg->GlobalData[0x24],int64to32(WrittenFileSize));
799
 
    VM.SetLowEndianValue((uint *)&Prg->GlobalData[0x28],int64to32(WrittenFileSize>>32));
 
797
    Prg->InitR[6]=(uint)WrittenFileSize;
 
798
    VM.SetLowEndianValue((uint *)&Prg->GlobalData[0x24],(uint)WrittenFileSize);
 
799
    VM.SetLowEndianValue((uint *)&Prg->GlobalData[0x28],(uint)(WrittenFileSize>>32));
800
800
    VM.Execute(Prg);
801
801
  }
802
802
}
808
808
    UnpSomeRead=true;
809
809
  if (EndPtr<StartPtr)
810
810
  {
811
 
    UnpWriteData(&Window[StartPtr],-StartPtr & MAXWINMASK);
 
811
    UnpWriteData(&Window[StartPtr],-(int)StartPtr & MAXWINMASK);
812
812
    UnpWriteData(Window,EndPtr);
813
813
    UnpAllBuf=true;
814
814
  }
817
817
}
818
818
 
819
819
 
820
 
void Unpack::UnpWriteData(byte *Data,int Size)
 
820
void Unpack::UnpWriteData(byte *Data,size_t Size)
821
821
{
822
822
  if (WrittenFileSize>=DestUnpSize)
823
823
    return;
824
 
  int WriteSize=Size;
825
 
  Int64 LeftToWrite=DestUnpSize-WrittenFileSize;
826
 
  if (WriteSize>LeftToWrite)
827
 
    WriteSize=int64to32(LeftToWrite);
 
824
  size_t WriteSize=Size;
 
825
  int64 LeftToWrite=DestUnpSize-WrittenFileSize;
 
826
  if ((int64)WriteSize>LeftToWrite)
 
827
    WriteSize=(size_t)LeftToWrite;
828
828
  UnpIO->UnpWrite(Data,WriteSize);
829
829
  WrittenFileSize+=Size;
830
830
}
973
973
  OldFilterLengths.Reset();
974
974
  LastFilter=0;
975
975
 
976
 
  for (int I=0;I<Filters.Size();I++)
 
976
  for (size_t I=0;I<Filters.Size();I++)
977
977
    delete Filters[I];
978
978
  Filters.Reset();
979
 
  for (int I=0;I<PrgStack.Size();I++)
 
979
  for (size_t I=0;I<PrgStack.Size();I++)
980
980
    delete PrgStack[I];
981
981
  PrgStack.Reset();
982
982
}