~louis/ubuntu/trusty/clamav/lp799623_fix_logrotate

« back to all changes in this revision

Viewing changes to libclamav/7z/Archive/7z/7zExtract.c

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-03-12 11:30:04 UTC
  • mfrom: (0.41.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100312113004-b0fop4bkycszdd0z
Tags: 0.96~rc1+dfsg-0ubuntu1
* New upstream RC - FFE (LP: #537636):
  - Add OfficialDatabaseOnly option to clamav-base.postinst.in
  - Add LocalSocketGroup option to clamav-base.postinst.in
  - Add LocalSocketMode option to clamav-base.postinst.in
  - Add CrossFilesystems option to clamav-base.postinst.in
  - Add ClamukoScannerCount option to clamav-base.postinst.in
  - Add BytecodeSecurity opiton to clamav-base.postinst.in
  - Add DetectionStatsHostID option to clamav-freshclam.postinst.in
  - Add Bytecode option to clamav-freshclam.postinst.in
  - Add MilterSocketGroup option to clamav-milter.postinst.in
  - Add MilterSocketMode option to clamav-milter.postinst.in
  - Add ReportHostname option to clamav-milter.postinst.in
  - Bump libclamav SO version to 6.1.0 in libclamav6.install
  - Drop clamdmon from clamav.examples (no longer shipped by upstream)
  - Drop libclamav.a from libclamav-dev.install (not built by upstream)
  - Update SO version for lintian override for libclamav6
  - Add new Bytecode Testing Tool, usr/bin/clambc, to clamav.install
  - Add build-depends on python and python-setuptools for new test suite
  - Update debian/copyright for the embedded copy of llvm (using the system
    llvm is not currently feasible)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 7zExtract.c -- Extracting from 7z archive
 
2
2008-11-23 : Igor Pavlov : Public domain */
 
3
 
 
4
#include "../../7zCrc.h"
 
5
#include "7zDecode.h"
 
6
#include "7zExtract.h"
 
7
 
 
8
SRes SzAr_Extract(
 
9
    const CSzArEx *p,
 
10
    ILookInStream *inStream,
 
11
    UInt32 fileIndex,
 
12
    UInt32 *blockIndex,
 
13
    Byte **outBuffer,
 
14
    size_t *outBufferSize,
 
15
    size_t *offset,
 
16
    size_t *outSizeProcessed,
 
17
    ISzAlloc *allocMain,
 
18
    ISzAlloc *allocTemp)
 
19
{
 
20
  UInt32 folderIndex = p->FileIndexToFolderIndexMap[fileIndex];
 
21
  SRes res = SZ_OK;
 
22
  *offset = 0;
 
23
  *outSizeProcessed = 0;
 
24
  if (folderIndex == (UInt32)-1)
 
25
  {
 
26
    IAlloc_Free(allocMain, *outBuffer);
 
27
    *blockIndex = folderIndex;
 
28
    *outBuffer = 0;
 
29
    *outBufferSize = 0;
 
30
    return SZ_OK;
 
31
  }
 
32
 
 
33
  if (*outBuffer == 0 || *blockIndex != folderIndex)
 
34
  {
 
35
    CSzFolder *folder = p->db.Folders + folderIndex;
 
36
    UInt64 unpackSizeSpec = SzFolder_GetUnpackSize(folder);
 
37
    size_t unpackSize = (size_t)unpackSizeSpec;
 
38
    UInt64 startOffset = SzArEx_GetFolderStreamPos(p, folderIndex, 0);
 
39
 
 
40
    if (unpackSize != unpackSizeSpec)
 
41
      return SZ_ERROR_MEM;
 
42
    *blockIndex = folderIndex;
 
43
    IAlloc_Free(allocMain, *outBuffer);
 
44
    *outBuffer = 0;
 
45
    
 
46
    RINOK(LookInStream_SeekTo(inStream, startOffset));
 
47
    
 
48
    if (res == SZ_OK)
 
49
    {
 
50
      *outBufferSize = unpackSize;
 
51
      if (unpackSize != 0)
 
52
      {
 
53
        *outBuffer = (Byte *)IAlloc_Alloc(allocMain, unpackSize);
 
54
        if (*outBuffer == 0)
 
55
          res = SZ_ERROR_MEM;
 
56
      }
 
57
      if (res == SZ_OK)
 
58
      {
 
59
        res = SzDecode(p->db.PackSizes +
 
60
          p->FolderStartPackStreamIndex[folderIndex], folder,
 
61
          inStream, startOffset,
 
62
          *outBuffer, unpackSize, allocTemp);
 
63
        if (res == SZ_OK)
 
64
        {
 
65
          if (folder->UnpackCRCDefined)
 
66
          {
 
67
            if (CrcCalc(*outBuffer, unpackSize) != folder->UnpackCRC)
 
68
              res = SZ_ERROR_CRC;
 
69
          }
 
70
        }
 
71
      }
 
72
    }
 
73
  }
 
74
  if (res == SZ_OK)
 
75
  {
 
76
    UInt32 i;
 
77
    CSzFileItem *fileItem = p->db.Files + fileIndex;
 
78
    *offset = 0;
 
79
    for (i = p->FolderStartFileIndex[folderIndex]; i < fileIndex; i++)
 
80
      *offset += (UInt32)p->db.Files[i].Size;
 
81
    *outSizeProcessed = (size_t)fileItem->Size;
 
82
    if (*offset + *outSizeProcessed > *outBufferSize)
 
83
      return SZ_ERROR_FAIL;
 
84
    {
 
85
      if (fileItem->FileCRCDefined)
 
86
      {
 
87
        if (CrcCalc(*outBuffer + *offset, *outSizeProcessed) != fileItem->FileCRC)
 
88
          res = SZ_ERROR_CRC;
 
89
      }
 
90
    }
 
91
  }
 
92
  return res;
 
93
}