VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common/zlib/uncompr.c
blob: f03a1a865e347d10ac16f6a70b2bc2fdc5235f9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* uncompr.c -- decompress a memory buffer
 * Copyright (C) 1995-2003, 2010, 2014, 2016 Jean-loup Gailly, Mark Adler
 * For conditions of distribution and use, see copyright notice in zlib.h
 */

/* @(#) $Id$ */

#define ZLIB_INTERNAL
#include "zlib.h"

/* ===========================================================================
     Decompresses the source buffer into the destination buffer.  *sourceLen is
   the byte length of the source buffer. Upon entry, *destLen is the total size
   of the destination buffer, which must be large enough to hold the entire
   uncompressed data. (The size of the uncompressed data must have been saved
   previously by the compressor and transmitted to the decompressor by some
   mechanism outside the scope of this compression library.) Upon exit,
   *destLen is the size of the decompressed data and *sourceLen is the number
   of source bytes consumed. Upon return, source + *sourceLen points to the
   first unused input byte.

     uncompress returns Z_OK if success, Z_MEM_ERROR if there was not enough
   memory, Z_BUF_ERROR if there was not enough room in the output buffer, or
   Z_DATA_ERROR if the input data was corrupted, including if the input data is
   an incomplete zlib stream.
*/
int ZEXPORT uncompress2 (dest, destLen, source, sourceLen)
    Bytef *dest;
    uLongf *destLen;
    const Bytef *source;
    uLong *sourceLen;
{
    z_stream stream;
    int err;
    const uInt max = (uInt)-1;
    uLong len, left;
    Byte buf[1];    /* for detection of incomplete stream when *destLen == 0 */

    len = *sourceLen;
    if (*destLen) {
        left = *destLen;
        *destLen = 0;
    }
    else {
        left = 1;
        dest = buf;
    }

    stream.next_in = (z_const Bytef *)source;
    stream.avail_in = 0;
    stream.zalloc = (alloc_func)0;
    stream.zfree = (free_func)0;
    stream.opaque = (voidpf)0;

    err = inflateInit(&stream);
    if (err != Z_OK) return err;

    stream.next_out = dest;
    stream.avail_out = 0;

    do {
        if (stream.avail_out == 0) {
            stream.avail_out = left > (uLong)max ? max : (uInt)left;
            left -= stream.avail_out;
        }
        if (stream.avail_in == 0) {
            stream.avail_in = len > (uLong)max ? max : (uInt)len;
            len -= stream.avail_in;
        }
        err = inflate(&stream, Z_NO_FLUSH);
    } while (err == Z_OK);

    *sourceLen -= len + stream.avail_in;
    if (dest != buf)
        *destLen = stream.total_out;
    else if (stream.total_out && err == Z_BUF_ERROR)
        left = 1;

    inflateEnd(&stream);
    return err == Z_STREAM_END ? Z_OK :
           err == Z_NEED_DICT ? Z_DATA_ERROR  :
           err == Z_BUF_ERROR && left + stream.avail_out ? Z_DATA_ERROR :
           err;
}

int ZEXPORT uncompress (dest, destLen, source, sourceLen)
    Bytef *dest;
    uLongf *destLen;
    const Bytef *source;
    uLong sourceLen;
{
    return uncompress2(dest, destLen, source, &sourceLen);
}
5060 #define IDC_KEYFILES_ENABLE 5061 #define IDT_HIDDEN_VOL_PROTECTION 5062 #define IDC_ADD_KEYFILE_PATH 5063 #define IDC_BENCHMARK_BUFFER_SIZE 5064 #define IDC_SHOW_PASSWORD_MO 5065 #define IDC_GENERATE_KEYFILE 5066 #define IDC_BENCHMARK_SORT_METHOD 5067 #define IDC_PASSWORD_PROT_HIDVOL 5068 #define IDT_BUFFER_SIZE 5069 #define IDC_LANGLIST 5070 #define IDC_KEYFILES_ENABLE_HIDVOL_PROT 5071 #define IDT_KEYFILES_NOTE 5072 #define IDT_KEYFILE_WARNING 5073 #define IDT_KEYFILE_GENERATOR_NOTE 5074 #define IDC_GENERATE_AND_SAVE_KEYFILE 5075 #define IDT_POOL_CONTENTS 5076 #define IDC_GET_LANG_PACKS 5077 #define IDT_LANGPACK_AUTHORS 5078 #define IDC_LANGPACK_CREDITS 5079 #define IDC_LANGPACK_VERSION 5080 #define IDT_ACTIVE_LANG_PACK 5081 #define IDC_DISPLAY_POOL_CONTENTS 5082 #define IDC_XTS_MODE_ENABLED 5083 #define IDC_MULTI_CHOICE_MSG 5084 #define IDC_CHOICE1 5085 #define IDC_CHOICE5 5086 #define IDC_CHOICE2 5087 #define IDC_CHOICE3 5088 #define IDC_CHOICE4 5089 #define IDC_CHOICE6 5090 #define IDC_CHOICE7 5091 #define IDC_CHOICE8 5092 #define IDC_CHOICE9 5093 #define IDC_CHOICE10 5094 #define IDC_MC_DLG_HR1 5095 #define IDC_MC_DLG_HR2 5096 #define IDC_LINK_HIDVOL_PROTECTION_INFO 5097 #define IDC_LINK_KEYFILES_INFO 5098 #define IDC_TEXTUAL_LOGO_IMG 5099 #define IDC_ASPECT_RATIO_CALIBRATION_BOX 5100 #define IDC_ABOUT_LOGO_AREA 5101 #define IDC_TOKEN_PASSWORD 5102 #define IDC_TOKEN_FILE_LIST 5103 #define IDC_TOKEN_FILES_ADD 5104 #define IDC_EXPORT 5105 #define IDC_DELETE 5106 #define IDC_IMPORT_KEYFILE 5107 #define IDC_SELECTED_TOKEN 5108 #define IDT_SECURITY_TOKEN 5109 #define IDT_TOKEN_KEYFILE_NAME 5110 #define IDC_TOKEN_KEYFILE_NAME 5111 #define IDT_TOKEN_PASSWORD_INFO 5112 #define IDT_RANDOM_POOL_ENRICHMENT_NOTE 5113 #define IDC_CONTINUE 5114 #define IDT_ABOUT_RELEASE 5115 #define IDT_STATIC_MODELESS_WAIT_DLG_INFO 5116 #define IDT_NUMBER_KEYFILES 5117 #define IDC_NUMBER_KEYFILES 5118 #define IDT_KEYFILES_BASE_NAME 5119 #define IDC_KEYFILES_BASE_NAME 5120 #define IDC_KEYFILES_SIZE 5121 #define IDC_KEYFILES_RANDOM_SIZE 5122 #define IDT_KEYFILES_SIZE 5123 #define IDD_STATIC_MODAL_WAIT_DLG 5124 #define IDT_STATIC_MODAL_WAIT_DLG_INFO 5125 #define IDC_WAIT_PROGRESS_BAR 5126 #define IDC_PKCS5_PRF_ID 5127 #define IDT_PKCS5_PRF 5128 #define IDT_PIM 5129 #define IDC_PIM 5130 #define IDC_PIM_HELP 5131 #define IDC_PIM_ENABLE 5132 #define IDC_VOLUME_LABEL 5133 #define IDT_VOLUME_LABEL 5134 #define IDC_KEYFILES_TRY_EMPTY_PASSWORD 5135 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NO_MFC 1 #define _APS_NEXT_RESOURCE_VALUE 542 #define _APS_NEXT_COMMAND_VALUE 40001 #define _APS_NEXT_CONTROL_VALUE 5136 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif