~ubuntu-branches/ubuntu/trusty/unrar-nonfree/trusty

« back to all changes in this revision

Viewing changes to unpack.cpp

  • Committer: Package Import Robot
  • Author(s): Nick Andrik
  • Date: 2013-02-19 22:31:18 UTC
  • mfrom: (1.1.16) (5.1.16 sid)
  • Revision ID: package-import@ubuntu.com-20130219223118-61qzgr8r12xkcv2n
Tags: 1:4.2.4-0.3
* Non-maintainer upload
* Another fix for symbols file to prevent FTBFS in many architectures

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
{
13
13
  UnpIO=DataIO;
14
14
  Window=NULL;
15
 
  ExternalWindow=false;
16
15
  Suspended=false;
17
16
  UnpAllBuf=false;
18
17
  UnpSomeRead=false;
21
20
 
22
21
Unpack::~Unpack()
23
22
{
24
 
  if (Window!=NULL && !ExternalWindow)
25
 
    delete[] Window;
 
23
  delete[] Window;
26
24
  InitFilters();
27
25
}
28
26
 
29
27
 
30
 
void Unpack::Init(byte *Window)
 
28
void Unpack::Init()
31
29
{
 
30
  Window=new byte[MAXWINSIZE];
 
31
 
 
32
#ifndef ALLOW_EXCEPTIONS
32
33
  if (Window==NULL)
33
 
  {
34
 
    Unpack::Window=new byte[MAXWINSIZE];
35
 
 
36
 
    // Clean the window to generate the same output when unpacking corrupt
37
 
    // RAR files, which may access to unused areas of sliding dictionary.
38
 
    memset(Unpack::Window,0,MAXWINSIZE);
39
 
#ifndef ALLOW_EXCEPTIONS
40
 
    if (Unpack::Window==NULL)
41
 
      ErrHandler.MemoryError();
 
34
    ErrHandler.MemoryError();
42
35
#endif
43
 
  }
44
 
  else
45
 
  {
46
 
    Unpack::Window=Window;
47
 
    ExternalWindow=true;
48
 
  }
 
36
 
 
37
  // Clean the window to generate the same output when unpacking corrupt
 
38
  // RAR files, which may access to unused areas of sliding dictionary.
 
39
  memset(Window,0,MAXWINSIZE);
 
40
 
49
41
  UnpInitData(false);
50
42
 
51
43
#ifndef SFX_MODULE
86
78
}
87
79
 
88
80
 
89
 
inline void Unpack::InsertLastMatch(unsigned int Length,unsigned int Distance)
90
 
{
91
 
  LastDist=Distance;
92
 
  LastLength=Length;
93
 
}
94
 
 
95
 
 
96
81
_forceinline void Unpack::CopyString(uint Length,uint Distance)
97
82
{
98
83
  uint SrcPtr=UnpPtr-Distance;
213
198
  if (DDecode[1]==0)
214
199
  {
215
200
    int Dist=0,BitLength=0,Slot=0;
216
 
    for (int I=0;I<sizeof(DBitLengthCounts)/sizeof(DBitLengthCounts[0]);I++,BitLength++)
 
201
    for (int I=0;I<ASIZE(DBitLengthCounts);I++,BitLength++)
217
202
      for (int J=0;J<DBitLengthCounts[I];J++,Slot++,Dist+=(1<<BitLength))
218
203
      {
219
204
        DDecode[Slot]=Dist;
275
260
        }
276
261
        if (NextCh==-1) // Corrupt PPM data found.
277
262
          break;
278
 
        if (NextCh==2)  // End of file in PPM mode..
 
263
        if (NextCh==2)  // End of file in PPM mode.
279
264
          break;
280
265
        if (NextCh==3)  // Read VM code.
281
266
        {
380
365
      }
381
366
 
382
367
      InsertOldDist(Distance);
383
 
      InsertLastMatch(Length,Distance);
 
368
      LastLength=Length;
384
369
      CopyString(Length,Distance);
385
370
      continue;
386
371
    }
399
384
    if (Number==258)
400
385
    {
401
386
      if (LastLength!=0)
402
 
        CopyString(LastLength,LastDist);
 
387
        CopyString(LastLength,OldDist[0]);
403
388
      continue;
404
389
    }
405
390
    if (Number<263)
417
402
        Length+=getbits()>>(16-Bits);
418
403
        addbits(Bits);
419
404
      }
420
 
      InsertLastMatch(Length,Distance);
 
405
      LastLength=Length;
421
406
      CopyString(Length,Distance);
422
407
      continue;
423
408
    }
430
415
        addbits(Bits);
431
416
      }
432
417
      InsertOldDist(Distance);
433
 
      InsertLastMatch(2,Distance);
 
418
      LastLength=2;
434
419
      CopyString(2,Distance);
435
420
      continue;
436
421
    }
439
424
}
440
425
 
441
426
 
 
427
// Return 'false' to quit unpacking the current file or 'true' to continue.
442
428
bool Unpack::ReadEndOfBlock()
443
429
{
444
430
  unsigned int BitField=getbits();
445
431
  bool NewTable,NewFile=false;
446
 
  if (BitField & 0x8000)
 
432
 
 
433
  // "1"  - no new file, new table just here.
 
434
  // "00" - new file,    no new table.
 
435
  // "01" - new file,    new table (in beginning of next file).
 
436
  
 
437
  if ((BitField & 0x8000)!=0)
447
438
  {
448
439
    NewTable=true;
449
440
    addbits(1);
455
446
    addbits(2);
456
447
  }
457
448
  TablesRead=!NewTable;
458
 
  return !(NewFile || NewTable && !ReadTables());
 
449
 
 
450
  // Quit immediately if "new file" flag is set. If "new table" flag
 
451
  // is present, we'll read the table in beginning of next file
 
452
  // based on 'TablesRead' 'false' value.
 
453
  if (NewFile)
 
454
    return false;
 
455
  return ReadTables(); // Quit only if we failed to read tables.
459
456
}
460
457
 
461
458
 
462
459
bool Unpack::ReadVMCode()
463
460
{
 
461
  // Entire VM code is guaranteed to fully present in block defined 
 
462
  // by current Huffman table. Compressor checks that VM code does not cross
 
463
  // Huffman block boundaries.
464
464
  unsigned int FirstByte=getbits()>>8;
465
465
  addbits(8);
466
466
  int Length=(FirstByte & 7)+1;
554
554
  if (NewFilter) // New filter code, never used before since VM reset.
555
555
  {
556
556
    // Too many different filters, corrupt archive.
557
 
    if (FiltPos>1024)
 
557
    if (FiltPos>MAX_FILTERS)
558
558
    {
559
559
      delete StackFilter;
560
560
      return false;
836
836
      }
837
837
      else
838
838
      {
 
839
        // Current filter intersects the window write border, so we adjust
 
840
        // the window border to process this filter next time, not now.
839
841
        for (size_t J=I;J<PrgStack.Size();J++)
840
842
        {
841
843
          UnpackFilter *flt=PrgStack[J];
1112
1114
 
1113
1115
      // Prepare the decode table, so this position in code list will be
1114
1116
      // decoded to current alphabet item number.
1115
 
      Dec->DecodeNum[LastPos]=I;
 
1117
      Dec->DecodeNum[LastPos]=(ushort)I;
1116
1118
 
1117
1119
      // We'll use next position number for this bit length next time.
1118
1120
      // So we pass through the entire range of positions available