~ubuntu-branches/ubuntu/precise/tiff/precise-security

« back to all changes in this revision

Viewing changes to .pc/CVE-2014-9655-2.patch/libtiff/tif_next.c

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2015-03-30 08:11:18 UTC
  • Revision ID: package-import@ubuntu.com-20150330081118-bvaoaii1act27voq
Tags: 3.9.5-2ubuntu1.7
* SECURITY UPDATE: Fix multiple security issues
  - debian/patches/CVE-2014-81xx-1.patch to CVE-2014-81xx-11.patch
  - debian/patches/CVE-2014-8128-5.patch
  - debian/patches/CVE-2014-9655-1.patch to CVE-2014-9655-3.patch
  - debian/patches/read_overrun.patch
  - debian/patches/CVE-2014-8130.patch
  - CVE-2014-8127 (partially)
  - CVE-2014-8128
  - CVE-2014-8129
  - CVE-2014-8130
  - CVE-2014-9330
  - CVE-2014-9655

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: tif_next.c,v 1.8.2.1 2010-06-08 18:50:42 bfriesen Exp $ */
 
2
 
 
3
/*
 
4
 * Copyright (c) 1988-1997 Sam Leffler
 
5
 * Copyright (c) 1991-1997 Silicon Graphics, Inc.
 
6
 *
 
7
 * Permission to use, copy, modify, distribute, and sell this software and 
 
8
 * its documentation for any purpose is hereby granted without fee, provided
 
9
 * that (i) the above copyright notices and this permission notice appear in
 
10
 * all copies of the software and related documentation, and (ii) the names of
 
11
 * Sam Leffler and Silicon Graphics may not be used in any advertising or
 
12
 * publicity relating to the software without the specific, prior written
 
13
 * permission of Sam Leffler and Silicon Graphics.
 
14
 * 
 
15
 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
 
16
 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
 
17
 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
 
18
 * 
 
19
 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
 
20
 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
 
21
 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
 
22
 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
 
23
 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
 
24
 * OF THIS SOFTWARE.
 
25
 */
 
26
 
 
27
#include "tiffiop.h"
 
28
#ifdef NEXT_SUPPORT
 
29
/*
 
30
 * TIFF Library.
 
31
 *
 
32
 * NeXT 2-bit Grey Scale Compression Algorithm Support
 
33
 */
 
34
 
 
35
#define SETPIXEL(op, v) {                       \
 
36
        switch (npixels++ & 3) {                \
 
37
        case 0: op[0]  = (unsigned char) ((v) << 6); break;     \
 
38
        case 1: op[0] |= (v) << 4; break;       \
 
39
        case 2: op[0] |= (v) << 2; break;       \
 
40
        case 3: *op++ |= (v);      break;       \
 
41
        }                                       \
 
42
}
 
43
 
 
44
#define LITERALROW      0x00
 
45
#define LITERALSPAN     0x40
 
46
#define WHITE           ((1<<2)-1)
 
47
 
 
48
static int
 
49
NeXTDecode(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
 
50
{
 
51
        unsigned char *bp, *op;
 
52
        tsize_t cc;
 
53
        tidata_t row;
 
54
        tsize_t scanline, n;
 
55
 
 
56
        (void) s;
 
57
        /*
 
58
         * Each scanline is assumed to start off as all
 
59
         * white (we assume a PhotometricInterpretation
 
60
         * of ``min-is-black'').
 
61
         */
 
62
        for (op = buf, cc = occ; cc-- > 0;)
 
63
                *op++ = 0xff;
 
64
 
 
65
        bp = (unsigned char *)tif->tif_rawcp;
 
66
        cc = tif->tif_rawcc;
 
67
        scanline = tif->tif_scanlinesize;
 
68
        for (row = buf; occ > 0; occ -= scanline, row += scanline) {
 
69
                n = *bp++, cc--;
 
70
                switch (n) {
 
71
                case LITERALROW:
 
72
                        /*
 
73
                         * The entire scanline is given as literal values.
 
74
                         */
 
75
                        if (cc < scanline)
 
76
                                goto bad;
 
77
                        _TIFFmemcpy(row, bp, scanline);
 
78
                        bp += scanline;
 
79
                        cc -= scanline;
 
80
                        break;
 
81
                case LITERALSPAN: {
 
82
                        tsize_t off;
 
83
                        /*
 
84
                         * The scanline has a literal span that begins at some
 
85
                         * offset.
 
86
                         */
 
87
                        off = (bp[0] * 256) + bp[1];
 
88
                        n = (bp[2] * 256) + bp[3];
 
89
                        if (cc < 4+n || off+n > scanline)
 
90
                                goto bad;
 
91
                        _TIFFmemcpy(row+off, bp+4, n);
 
92
                        bp += 4+n;
 
93
                        cc -= 4+n;
 
94
                        break;
 
95
                }
 
96
                default: {
 
97
                        uint32 npixels = 0, grey;
 
98
                        uint32 imagewidth = tif->tif_dir.td_imagewidth;
 
99
            if( isTiled(tif) )
 
100
                imagewidth = tif->tif_dir.td_tilewidth;
 
101
 
 
102
                        /*
 
103
                         * The scanline is composed of a sequence of constant
 
104
                         * color ``runs''.  We shift into ``run mode'' and
 
105
                         * interpret bytes as codes of the form
 
106
                         * <color><npixels> until we've filled the scanline.
 
107
                         */
 
108
                        op = row;
 
109
                        for (;;) {
 
110
                                grey = (n>>6) & 0x3;
 
111
                                n &= 0x3f;
 
112
                                /*
 
113
                                 * Ensure the run does not exceed the scanline
 
114
                                 * bounds, potentially resulting in a security
 
115
                                 * issue.
 
116
                                 */
 
117
                                while (n-- > 0 && npixels < imagewidth)
 
118
                                        SETPIXEL(op, grey);
 
119
                                if (npixels >= imagewidth)
 
120
                                        break;
 
121
                                if (cc == 0)
 
122
                                        goto bad;
 
123
                                n = *bp++, cc--;
 
124
                        }
 
125
                        break;
 
126
                }
 
127
                }
 
128
        }
 
129
        tif->tif_rawcp = (tidata_t) bp;
 
130
        tif->tif_rawcc = cc;
 
131
        return (1);
 
132
bad:
 
133
        TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "NeXTDecode: Not enough data for scanline %ld",
 
134
            (long) tif->tif_row);
 
135
        return (0);
 
136
}
 
137
 
 
138
static int
 
139
NeXTPreDecode(TIFF* tif, uint16 s)
 
140
{
 
141
        static const char module[] = "NeXTPreDecode";
 
142
        TIFFDirectory *td = &tif->tif_dir;
 
143
        (void)s;
 
144
 
 
145
        if( td->td_bitspersample != 2 )
 
146
        {
 
147
                TIFFErrorExt(tif->tif_clientdata, module, "Unsupported BitsPerSample = %d",
 
148
                                         td->td_bitspersample);
 
149
                return (0);
 
150
        }
 
151
        return (1);
 
152
}
 
153
 
 
154
int
 
155
TIFFInitNeXT(TIFF* tif, int scheme)
 
156
{
 
157
        (void) scheme;
 
158
        tif->tif_predecode = NeXTPreDecode;
 
159
        tif->tif_decoderow = NeXTDecode;
 
160
        tif->tif_decodestrip = NeXTDecode;
 
161
        tif->tif_decodetile = NeXTDecode;
 
162
        return (1);
 
163
}
 
164
#endif /* NEXT_SUPPORT */
 
165
 
 
166
/* vim: set ts=8 sts=8 sw=8 noet: */
 
167
/*
 
168
 * Local Variables:
 
169
 * mode: c
 
170
 * c-basic-offset: 8
 
171
 * fill-column: 78
 
172
 * End:
 
173
 */