~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/lib/zlib/uncompr.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Xorg: uncompr.c,v 1.3 2000/08/17 19:46:48 cpqbld Exp $ */
 
2
/* uncompr.c -- decompress a memory buffer
 
3
 * Copyright (C) 1995-1998 Jean-loup Gailly.
 
4
 * For conditions of distribution and use, see copyright notice in zlib.h 
 
5
 */
 
6
 
 
7
#include "zlib.h"
 
8
 
 
9
/* ===========================================================================
 
10
     Decompresses the source buffer into the destination buffer.  sourceLen is
 
11
   the byte length of the source buffer. Upon entry, destLen is the total
 
12
   size of the destination buffer, which must be large enough to hold the
 
13
   entire uncompressed data. (The size of the uncompressed data must have
 
14
   been saved previously by the compressor and transmitted to the decompressor
 
15
   by some mechanism outside the scope of this compression library.)
 
16
   Upon exit, destLen is the actual size of the compressed buffer.
 
17
     This function can be used to decompress a whole file at once if the
 
18
   input file is mmap'ed.
 
19
 
 
20
     uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
 
21
   enough memory, Z_BUF_ERROR if there was not enough room in the output
 
22
   buffer, or Z_DATA_ERROR if the input data was corrupted.
 
23
*/
 
24
int EXPORT uncompress (dest, destLen, source, sourceLen)
 
25
    Bytef *dest;
 
26
    uLongf *destLen;
 
27
    const Bytef *source;
 
28
    uLong sourceLen;
 
29
{
 
30
    z_stream stream;
 
31
    int err;
 
32
 
 
33
    stream.next_in = (Bytef*)source;
 
34
    stream.avail_in = (uInt)sourceLen;
 
35
    /* Check for source > 64K on 16-bit machine: */
 
36
    if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
 
37
 
 
38
    stream.next_out = dest;
 
39
    stream.avail_out = (uInt)*destLen;
 
40
    if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
 
41
 
 
42
    stream.zalloc = (alloc_func)0;
 
43
    stream.zfree = (free_func)0;
 
44
 
 
45
    err = inflateInit(&stream);
 
46
    if (err != Z_OK) return err;
 
47
 
 
48
    err = inflate(&stream, Z_FINISH);
 
49
    if (err != Z_STREAM_END) {
 
50
        inflateEnd(&stream);
 
51
        return err == Z_OK ? Z_BUF_ERROR : err;
 
52
    }
 
53
    *destLen = stream.total_out;
 
54
 
 
55
    err = inflateEnd(&stream);
 
56
    return err;
 
57
}