Annotation of elwix/tools/oldlzma/SRC/7zip/Archive/7z_C/7zExtract.c, revision 1.1

1.1     ! misho       1: /* 7zExtract.c */
        !             2: 
        !             3: #include "7zExtract.h"
        !             4: #include "7zDecode.h"
        !             5: #include "7zCrc.h"
        !             6: 
        !             7: SZ_RESULT SzExtract(
        !             8:     ISzInStream *inStream, 
        !             9:     CArchiveDatabaseEx *db,
        !            10:     UInt32 fileIndex,
        !            11:     UInt32 *blockIndex,
        !            12:     Byte **outBuffer, 
        !            13:     size_t *outBufferSize,
        !            14:     size_t *offset, 
        !            15:     size_t *outSizeProcessed, 
        !            16:     ISzAlloc *allocMain,
        !            17:     ISzAlloc *allocTemp)
        !            18: {
        !            19:   UInt32 folderIndex = db->FileIndexToFolderIndexMap[fileIndex];
        !            20:   SZ_RESULT res = SZ_OK;
        !            21:   *offset = 0;
        !            22:   *outSizeProcessed = 0;
        !            23:   if (folderIndex == (UInt32)-1)
        !            24:   {
        !            25:     allocMain->Free(*outBuffer);
        !            26:     *blockIndex = folderIndex;
        !            27:     *outBuffer = 0;
        !            28:     *outBufferSize = 0;
        !            29:     return SZ_OK;
        !            30:   }
        !            31: 
        !            32:   if (*outBuffer == 0 || *blockIndex != folderIndex)
        !            33:   {
        !            34:     CFolder *folder = db->Database.Folders + folderIndex;
        !            35:     CFileSize unPackSize = SzFolderGetUnPackSize(folder);
        !            36:     #ifndef _LZMA_IN_CB
        !            37:     CFileSize packSize = SzArDbGetFolderFullPackSize(db, folderIndex);
        !            38:     Byte *inBuffer = 0;
        !            39:     size_t processedSize;
        !            40:     #endif
        !            41:     *blockIndex = folderIndex;
        !            42:     allocMain->Free(*outBuffer);
        !            43:     *outBuffer = 0;
        !            44:     
        !            45:     RINOK(inStream->Seek(inStream, SzArDbGetFolderStreamPos(db, folderIndex, 0)));
        !            46:     
        !            47:     #ifndef _LZMA_IN_CB
        !            48:     inBuffer = (Byte *)allocTemp->Alloc((size_t)packSize);
        !            49:     if (inBuffer == 0)
        !            50:       return SZE_OUTOFMEMORY;
        !            51:     res = inStream->Read(inStream, inBuffer, (size_t)packSize, &processedSize);
        !            52:     if (res == SZ_OK && processedSize != (size_t)packSize)
        !            53:       res = SZE_FAIL;
        !            54:     #endif
        !            55:     if (res == SZ_OK)
        !            56:     {
        !            57:       *outBuffer = (Byte *)allocMain->Alloc((size_t)unPackSize);
        !            58:       *outBufferSize = (size_t)unPackSize;
        !            59:       if (*outBuffer != 0)
        !            60:       {
        !            61:         size_t outRealSize;
        !            62:         res = SzDecode(db->Database.PackSizes + 
        !            63:           db->FolderStartPackStreamIndex[folderIndex], folder, 
        !            64:           #ifdef _LZMA_IN_CB
        !            65:           inStream,
        !            66:           #else
        !            67:           inBuffer, 
        !            68:           #endif
        !            69:           *outBuffer, (size_t)unPackSize, &outRealSize, allocTemp);
        !            70:         if (res == SZ_OK)
        !            71:         {
        !            72:           if (outRealSize == (size_t)unPackSize)
        !            73:           {
        !            74:             if (folder->UnPackCRCDefined)
        !            75:             {
        !            76:               if (!CrcVerifyDigest(folder->UnPackCRC, *outBuffer, (size_t)unPackSize))
        !            77:                 res = SZE_FAIL;
        !            78:             }
        !            79:           }
        !            80:           else
        !            81:             res = SZE_FAIL;
        !            82:         }
        !            83:       }
        !            84:       else
        !            85:         res = SZE_OUTOFMEMORY;
        !            86:     }
        !            87:     #ifndef _LZMA_IN_CB
        !            88:     allocTemp->Free(inBuffer);
        !            89:     #endif
        !            90:   }
        !            91:   if (res == SZ_OK)
        !            92:   {
        !            93:     UInt32 i; 
        !            94:     CFileItem *fileItem = db->Database.Files + fileIndex;
        !            95:     *offset = 0;
        !            96:     for(i = db->FolderStartFileIndex[folderIndex]; i < fileIndex; i++)
        !            97:       *offset += (UInt32)db->Database.Files[i].Size;
        !            98:     *outSizeProcessed = (size_t)fileItem->Size;
        !            99:     if (*offset + *outSizeProcessed > *outBufferSize)
        !           100:       return SZE_FAIL;
        !           101:     {
        !           102:       if (fileItem->IsFileCRCDefined)
        !           103:       {
        !           104:         if (!CrcVerifyDigest(fileItem->FileCRC, *outBuffer + *offset, *outSizeProcessed))
        !           105:           res = SZE_FAIL;
        !           106:       }
        !           107:     }
        !           108:   }
        !           109:   return res;
        !           110: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>